Message71085
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' |
|
Date |
User |
Action |
Args |
2008-08-13 16:02:07 | pitrou | set | recipients:
+ pitrou, gvanrossum, loewis, jimjjewett, janssen, orsenthil, thomaspinckney3, mgiuca |
2008-08-13 16:02:06 | pitrou | link | issue3300 messages |
2008-08-13 16:02:05 | pitrou | create | |
|