Antoine Pitrou <[EMAIL PROTECTED]> added the comment: Selon Matt Giuca <[EMAIL PROTECTED]>: > > > 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' _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3300> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com