[Patches] [ python-Patches-552433 ] Looping Optimization
noreply@sourceforge.net
noreply@sourceforge.net
Sat, 04 May 2002 22:13:46 -0700
Patches item #552433, was opened at 2002-05-05 03:35
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=552433&group_id=5470
>Category: Core (C code)
>Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Nobody/Anonymous (nobody)
Summary: Looping Optimization
Initial Comment:
Optimized the inner loop for iterobjects resulting in
a 19% speed-up for tuples and a 15% improvement for
strings and xrange objects. Dictionaries and lists
are unaffected (already handled as a special case or
with their own iterators).
1. Replaced PyList_Check with PyList_CheckExact.
Loses the special case handling for list subtypes but
gains speed because PyList_Check called the slow
function, PyType_IsSubtype.
2. Added special case handling for tuples. Identical
to the existing special case for lists (calls ob_size
and ob->item[i] directly).
3. Replaced the call to PySequence_GetItem function
with a macro for direct access to the sequence's
sq_item slot. Saves a function call, unnecessary
(previously checked) checks for tp_as_sequence and
sq_item, and an unnecessary check for negative indices
(sq_item has its own checks).
This small patch speeds-up looping throughout Python
whether it is called through list(seq), a for-loop, or
a functional.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=552433&group_id=5470