mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
GH-96793: Change FOR_ITER
to not pop the iterator on exhaustion. (GH-96801)
Change FOR_ITER to have the same stack effect regardless of whether it branches or not. Performance is unchanged as FOR_ITER (and specialized forms jump over the cleanup code).
This commit is contained in:
parent
e60892f9db
commit
22863df7ca
14 changed files with 277 additions and 247 deletions
|
@ -1298,6 +1298,14 @@ handle_eval_breaker:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(END_FOR) {
|
||||
PyObject *value = POP();
|
||||
Py_DECREF(value);
|
||||
value = POP();
|
||||
Py_DECREF(value);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(UNARY_POSITIVE) {
|
||||
PyObject *value = TOP();
|
||||
PyObject *res = PyNumber_Positive(value);
|
||||
|
@ -3844,9 +3852,11 @@ handle_eval_breaker:
|
|||
_PyErr_Clear(tstate);
|
||||
}
|
||||
/* iterator ended normally */
|
||||
assert(_Py_OPCODE(next_instr[INLINE_CACHE_ENTRIES_FOR_ITER + oparg] == END_FOR));
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(iter);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
|
||||
/* Skip END_FOR */
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -3884,7 +3894,7 @@ handle_eval_breaker:
|
|||
}
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(it);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -3898,7 +3908,7 @@ handle_eval_breaker:
|
|||
if (r->index >= r->len) {
|
||||
STACK_SHRINK(1);
|
||||
Py_DECREF(r);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
|
||||
JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
|
||||
DISPATCH();
|
||||
}
|
||||
long value = (long)(r->start +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue