mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +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
|
@ -413,6 +413,15 @@ The Python compiler currently generates the following bytecode instructions.
|
|||
Removes the top-of-stack (TOS) item.
|
||||
|
||||
|
||||
.. opcode:: END_FOR
|
||||
|
||||
Removes the top two values from the stack.
|
||||
Equivalent to POP_TOP; POP_TOP.
|
||||
Used to clean up at the end of loops, hence the name.
|
||||
|
||||
.. versionadded:: 3.12
|
||||
|
||||
|
||||
.. opcode:: COPY (i)
|
||||
|
||||
Push the *i*-th item to the top of the stack. The item is not removed from its
|
||||
|
@ -1088,9 +1097,11 @@ iterations of the loop.
|
|||
|
||||
TOS is an :term:`iterator`. Call its :meth:`~iterator.__next__` method. If
|
||||
this yields a new value, push it on the stack (leaving the iterator below
|
||||
it). If the iterator indicates it is exhausted, TOS is popped, and the byte
|
||||
it). If the iterator indicates it is exhausted then the byte
|
||||
code counter is incremented by *delta*.
|
||||
|
||||
.. versionchanged:: 3.12
|
||||
Up until 3.11 the iterator was popped when it was exhausted.
|
||||
|
||||
.. opcode:: LOAD_GLOBAL (namei)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue