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.
This commit is contained in:
Paul Sokolovsky 2015-05-11 02:59:25 +03:00 committed by Damien George
parent aa9dbb1b03
commit d5e629ad0e
1 changed files with 5 additions and 3 deletions

View File

@ -171,10 +171,12 @@ 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
// too, which may not handled MP_OBJ_STOP_ITERATION.
if (mp_obj_is_subclass_fast(mp_obj_get_type(ret), &mp_type_StopIteration)) {
return MP_OBJ_STOP_ITERATION;
} else {
nlr_raise(ret);
mp_obj_t val = mp_obj_exception_get_value(ret);
if (val == mp_const_none) {
return MP_OBJ_STOP_ITERATION;
}
}
nlr_raise(ret);
}
}