mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
GH-96793: Specialize FOR_ITER for generators. (GH-98772)
This commit is contained in:
parent
80c08d1cd6
commit
4a1c58d504
13 changed files with 207 additions and 71 deletions
|
@ -2184,7 +2184,7 @@ int
|
|||
#endif
|
||||
|
||||
void
|
||||
_Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr)
|
||||
_Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr, int oparg)
|
||||
{
|
||||
assert(_PyOpcode_Caches[FOR_ITER] == INLINE_CACHE_ENTRIES_FOR_ITER);
|
||||
_PyForIterCache *cache = (_PyForIterCache *)(instr + 1);
|
||||
|
@ -2199,6 +2199,11 @@ _Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr)
|
|||
_Py_SET_OPCODE(*instr, FOR_ITER_RANGE);
|
||||
goto success;
|
||||
}
|
||||
else if (tp == &PyGen_Type && oparg <= SHRT_MAX) {
|
||||
assert(_Py_OPCODE(instr[oparg + INLINE_CACHE_ENTRIES_FOR_ITER + 1]) == END_FOR);
|
||||
_Py_SET_OPCODE(*instr, FOR_ITER_GEN);
|
||||
goto success;
|
||||
}
|
||||
SPECIALIZATION_FAIL(FOR_ITER,
|
||||
_PySpecialization_ClassifyIterator(iter));
|
||||
STAT_INC(FOR_ITER, failure);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue