diff options
author | Damien George <damien.p.george@gmail.com> | 2016-09-18 23:59:47 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-09-19 12:23:31 +1000 |
commit | a5624bf3818c573611b2b7bfc755e27de97f64e4 (patch) | |
tree | 3584edbd6aca23455535a471e89d18b2ac5e1500 /py/compile.c | |
parent | 4b3f1d712b845a44a0d2680197cfb6c3fe4478bd (diff) |
py: Combine 3 comprehension emit functions (list/dict/set) into 1.
The 3 kinds of comprehensions are similar enough that merging their emit
functions reduces code size. Decreases in code size in bytes are:
bare-arm:24, minimal:96, unix(NDEBUG,x86-64):328, stmhal:80, esp8266:76.
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/py/compile.c b/py/compile.c index c8b4e5470..7207ac2e0 100644 --- a/py/compile.c +++ b/py/compile.c @@ -2869,17 +2869,11 @@ STATIC void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_struct_t *pn if (MP_PARSE_NODE_IS_NULL(pn_iter)) { // no more nested if/for; compile inner expression compile_node(comp, pn_inner_expr); - if (comp->scope_cur->kind == SCOPE_LIST_COMP) { - EMIT_ARG(list_append, for_depth + 2); - } else if (comp->scope_cur->kind == SCOPE_DICT_COMP) { - EMIT_ARG(map_add, for_depth + 2); - #if MICROPY_PY_BUILTINS_SET - } else if (comp->scope_cur->kind == SCOPE_SET_COMP) { - EMIT_ARG(set_add, for_depth + 2); - #endif - } else { + if (comp->scope_cur->kind == SCOPE_GEN_EXPR) { EMIT(yield_value); EMIT(pop_top); + } else { + EMIT_ARG(store_comp, comp->scope_cur->kind, for_depth + 2); } } else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn_iter, PN_comp_if)) { // if condition |