Skip to content

Commit d5e629a

Browse files
pfalcondpgeorge
authored andcommitted
objgenerator: Can optimize StopIteration to STOP_ITERATION only if arg is None.
Unfortunately, MP_OBJ_STOP_ITERATION doesn't have means to pass an associated value, so we can't optimize StopIteration exception with (non-None) argument to MP_OBJ_STOP_ITERATION.
1 parent aa9dbb1 commit d5e629a

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

py/objgenerator.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_o
171171
// of mp_iternext() protocol, but this function is called by other methods
172172
// too, which may not handled MP_OBJ_STOP_ITERATION.
173173
if (mp_obj_is_subclass_fast(mp_obj_get_type(ret), &mp_type_StopIteration)) {
174-
return MP_OBJ_STOP_ITERATION;
175-
} else {
176-
nlr_raise(ret);
174+
mp_obj_t val = mp_obj_exception_get_value(ret);
175+
if (val == mp_const_none) {
176+
return MP_OBJ_STOP_ITERATION;
177+
}
177178
}
179+
nlr_raise(ret);
178180
}
179181
}
180182

0 commit comments

Comments
 (0)