This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients gvanrossum, janssen, jimjjewett, loewis, mgiuca, orsenthil, pitrou, thomaspinckney3
Date 2008-08-13.16:02:05
SpamBayes Score 1.4956523e-06
Marked as misclassified No
Message-id <1218643340.48a3058cd4021@imp.free.fr>
In-reply-to <1218640140.82.0.343772051654.issue3300@psf.upfronthosting.co.za>
Content
Selon Matt Giuca <report@bugs.python.org>:
>
> > Now that you've spent so  much time with this patch, can't you think
> > of a faster way of doing this?
>
> Well firstly, you could replace Quoter (the class) with a "quoter"
> function, which is nested inside quote. Would calling a nested function
> be faster than a method call?

The obvious speedup is to remove the map() call and do the loop inside
Quoter.__call__ instead. That way you don't have any function or method call in
the critical path.

(also, defining a class with a single __call__ method is not a common Python
idiom; usually you'd just have a function returning another (nested) function)

As for the defaultdict, here is how it can look like (this is on 2.5):

...  def __missing__(self, key):
...   print "__missing__", key
...   value = "%%%02X" % key
...   self[key] = value
...   return value
...
>>> d = D()
>>> d[66] = 'B'
>>> d[66]
'B'
>>> d[67]
__missing__ 67
'%43'
>>> d[67]
'%43'
History
Date User Action Args
2008-08-13 16:02:07pitrousetrecipients: + pitrou, gvanrossum, loewis, jimjjewett, janssen, orsenthil, thomaspinckney3, mgiuca
2008-08-13 16:02:06pitroulinkissue3300 messages
2008-08-13 16:02:05pitroucreate