[issue4174] Performance optimization for min() and max() over lists
Antoine Pitrou
report at bugs.python.org
Wed Oct 22 20:53:09 CEST 2008
Antoine Pitrou <pitrou at free.fr> added the comment:
I haven't tried the patch as is but I can spot two problems:
- you should use PyList_CheckExact instead of PyList_Check, because a
list subclass could override __getitem__
- when keyfunc is not NULL, you can't assume that the list size will
stay constant; indeed, calling keyfunc may mutate the list (try
something like `max(l, key=l.pop)`)
I've got no opinion on whether the speedup is worth the added
complexity. Perhaps a way of simplifying the patch would be to enable
the special path only when keyfunc==NULL. Others may comment.
----------
nosy: +pitrou, rhettinger
versions: +Python 2.7, Python 3.1 -Python 2.5.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4174>
_______________________________________
More information about the Python-bugs-list
mailing list