summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-03-12 08:41:36 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-03-12 08:41:36 (GMT)
commitdb0de9e7cabc5e7bc052dfc4c8fc1b5dea154009 (patch)
treeb197929508f9f4ae866f72cd7453a712d5327dca
parentc1e4f9dd92a2b63b26b06035f8c8ee1a5eb52ab3 (diff)
downloadcpython-db0de9e7cabc5e7bc052dfc4c8fc1b5dea154009.zip
cpython-db0de9e7cabc5e7bc052dfc4c8fc1b5dea154009.tar.gz
cpython-db0de9e7cabc5e7bc052dfc4c8fc1b5dea154009.tar.bz2
Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
and a function call resulting in a 15% reduction of total loop overhead (as measured by timeit.Timer('pass')).
-rw-r--r--Python/ceval.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 1e724c5..3c9076c 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2091,21 +2091,23 @@ eval_frame(PyFrameObject *f)
case FOR_ITER:
/* before: [iter]; after: [iter, iter()] *or* [] */
v = TOP();
- x = PyIter_Next(v);
+ x = (*v->ob_type->tp_iternext)(v);
if (x != NULL) {
PUSH(x);
PREDICT(STORE_FAST);
PREDICT(UNPACK_SEQUENCE);
continue;
}
- if (!PyErr_Occurred()) {
- /* iterator ended normally */
- x = v = POP();
- Py_DECREF(v);
- JUMPBY(oparg);
- continue;
+ if (PyErr_Occurred()) {
+ if (!PyErr_ExceptionMatches(PyExc_StopIteration))
+ break;
+ PyErr_Clear();
}
- break;
+ /* iterator ended normally */
+ x = v = POP();
+ Py_DECREF(v);
+ JUMPBY(oparg);
+ continue;
case SETUP_LOOP:
case SETUP_EXCEPT: