[issue10160] operator.attrgetter slower than lambda after adding dotted names ability
Χρήστος Γεωργίου (Christos Georgiou)
report at bugs.python.org
Thu Oct 21 02:40:53 CEST 2010
Χρήστος Γεωργίου (Christos Georgiou) <tzot at users.sourceforge.net> added the comment:
An explanation to the changes.
The old code kept the operator.itemgetter arguments in the ag->attr member. If the argument count (ag->nattrs) was 1, the single argument was kept; if more than 1, a tuple of the original arguments was kept.
On every attrgetter_call call, if ag->nattrs was 1, dotted_getattr was called with the plain ag->attr as attribute name; if > 2, dotted_getattr was called for every one of the original arguments.
Now, ag->attr is always a tuple, containing either dotless strings or tuples of dotless strings:
operator.attrgetter("name1", "name2.name3", "name4")
stores ("name1", ("name2", "name3"), "name4") in ag->attr.
dotted_getattr accordingly chooses based on type (either str or tuple, ensured by attrgetter_new) whether to do a single access or a recursive one.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10160>
_______________________________________
More information about the Python-bugs-list
mailing list