mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
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')).
This commit is contained in:
parent
c1e4f9dd92
commit
db0de9e7ca
1 changed files with 10 additions and 8 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue