Skip to content
Snippets Groups Projects
Commit d5e629ad authored by Paul Sokolovsky's avatar Paul Sokolovsky Committed by Damien George
Browse files

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.
parent aa9dbb1b
No related branches found
No related tags found
No related merge requests found
...@@ -171,11 +171,13 @@ STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_o ...@@ -171,11 +171,13 @@ STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_o
// of mp_iternext() protocol, but this function is called by other methods // of mp_iternext() protocol, but this function is called by other methods
// too, which may not handled MP_OBJ_STOP_ITERATION. // too, which may not handled MP_OBJ_STOP_ITERATION.
if (mp_obj_is_subclass_fast(mp_obj_get_type(ret), &mp_type_StopIteration)) { if (mp_obj_is_subclass_fast(mp_obj_get_type(ret), &mp_type_StopIteration)) {
mp_obj_t val = mp_obj_exception_get_value(ret);
if (val == mp_const_none) {
return MP_OBJ_STOP_ITERATION; return MP_OBJ_STOP_ITERATION;
} else {
nlr_raise(ret);
} }
} }
nlr_raise(ret);
}
} }
STATIC mp_obj_t gen_instance_iternext(mp_obj_t self_in) { STATIC mp_obj_t gen_instance_iternext(mp_obj_t self_in) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment