From 22863df7ca5f9cd01a40ab3dce3d067ec5666081 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Thu, 27 Oct 2022 03:55:03 -0700 Subject: 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). --- Python/specialize.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'Python/specialize.c') diff --git a/Python/specialize.c b/Python/specialize.c index b7c321e487..6e2fa4e25f 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -2208,12 +2208,8 @@ _Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr) _Py_SET_OPCODE(*instr, FOR_ITER_RANGE); goto success; } - else { - SPECIALIZATION_FAIL(FOR_ITER, - _PySpecialization_ClassifyIterator(iter)); - goto failure; - } -failure: + SPECIALIZATION_FAIL(FOR_ITER, + _PySpecialization_ClassifyIterator(iter)); STAT_INC(FOR_ITER, failure); cache->counter = adaptive_counter_backoff(cache->counter); return; -- cgit v1.2.1