diff options
author | Mark Shannon <mark@hotpy.org> | 2022-11-07 14:49:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 14:49:51 (GMT) |
commit | 4a1c58d504a49eeb9be7beef3ca861a9d6b28ede (patch) | |
tree | 8c5245a6a3a19a311d0d5a31723da1225a2c6795 /Python/specialize.c | |
parent | 80c08d1cd67afdd1336c65ba23a044b6ac490f33 (diff) | |
download | cpython-4a1c58d504a49eeb9be7beef3ca861a9d6b28ede.zip cpython-4a1c58d504a49eeb9be7beef3ca861a9d6b28ede.tar.gz cpython-4a1c58d504a49eeb9be7beef3ca861a9d6b28ede.tar.bz2 |
GH-96793: Specialize FOR_ITER for generators. (GH-98772)
Diffstat (limited to 'Python/specialize.c')
-rw-r--r-- | Python/specialize.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Python/specialize.c b/Python/specialize.c index 70a456c..5717991 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -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); |