Browse Source

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.
pull/1247/merge
Paul Sokolovsky 10 years ago
committed by Damien George
parent
commit
d5e629ad0e
  1. 8
      py/objgenerator.c

8
py/objgenerator.c

@ -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);
}
}

Loading…
Cancel
Save