diff options
author | Damien George <damien.p.george@gmail.com> | 2018-06-29 16:32:58 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-07-02 15:30:57 +1000 |
commit | b488a4a8480533a6a3c9468c2f8bd359c94d4d02 (patch) | |
tree | 709b6ca9495c832856f54e03bc4db3055c861cb0 /py/emitglue.c | |
parent | 8f86fbfd6c34a4d03f2bd62e9dc1ff59c236b037 (diff) | |
download | micropython-b488a4a8480533a6a3c9468c2f8bd359c94d4d02.tar.gz micropython-b488a4a8480533a6a3c9468c2f8bd359c94d4d02.zip |
py/objgenerator: Eliminate need for mp_obj_gen_wrap wrapper instances.
For generating functions there is no need to wrap the bytecode function in
a generator wrapper instance. Instead the type of the bytecode function
can be changed to mp_type_gen_wrap. This reduces code size and saves a
block of GC heap RAM for each generator.
Diffstat (limited to 'py/emitglue.c')
-rw-r--r-- | py/emitglue.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/py/emitglue.c b/py/emitglue.c index 74bf8ddca2..a7fff0e0eb 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -146,14 +146,13 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar // rc->kind should always be set and BYTECODE is the only remaining case assert(rc->kind == MP_CODE_BYTECODE); fun = mp_obj_new_fun_bc(def_args, def_kw_args, rc->data.u_byte.bytecode, rc->data.u_byte.const_table); + // check for generator functions and if so change the type of the object + if ((rc->scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0) { + ((mp_obj_base_t*)MP_OBJ_TO_PTR(fun))->type = &mp_type_gen_wrap; + } break; } - // check for generator functions and if so wrap in generator object - if ((rc->scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0) { - fun = mp_obj_new_gen_wrap(fun); - } - return fun; } |