diff options
author | Damien George <damien.p.george@gmail.com> | 2017-04-22 14:23:47 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-04-22 14:23:47 +1000 |
commit | 40b40ffc98627b32adf83f3d657d237a9c59acca (patch) | |
tree | 1e6882972458d08e4be13986e1d2d1b4fd6af49a /py | |
parent | fa03bbf0fd0a2f5a5c21472a56e39ba60f7f58dd (diff) | |
download | micropython-40b40ffc98627b32adf83f3d657d237a9c59acca.tar.gz micropython-40b40ffc98627b32adf83f3d657d237a9c59acca.zip |
py/compile: Extract parse-node kind at start of func for efficiency.
Otherwise the type of parse-node and its kind has to be re-extracted
multiple times. This optimisation reduces code size by a bit (16 bytes on
bare-arm).
Diffstat (limited to 'py')
-rw-r--r-- | py/compile.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/py/compile.c b/py/compile.c index b114f8962c..3aa70e8bf2 100644 --- a/py/compile.c +++ b/py/compile.c @@ -586,8 +586,16 @@ STATIC void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int } STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) { - if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_typedargslist_star) - || MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_varargslist_star)) { + // For efficiency of the code below we extract the parse-node kind here + int pn_kind; + if (MP_PARSE_NODE_IS_ID(pn)) { + pn_kind = -1; + } else { + assert(MP_PARSE_NODE_IS_STRUCT(pn)); + pn_kind = MP_PARSE_NODE_STRUCT_KIND((mp_parse_node_struct_t*)pn); + } + + if (pn_kind == PN_typedargslist_star || pn_kind == PN_varargslist_star) { comp->have_star = true; /* don't need to distinguish bare from named star mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; @@ -598,8 +606,7 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) } */ - } else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_typedargslist_dbl_star) - || MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_varargslist_dbl_star)) { + } else if (pn_kind == PN_typedargslist_dbl_star || pn_kind == PN_varargslist_dbl_star) { // named double star // TODO do we need to do anything with this? @@ -607,14 +614,14 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) mp_parse_node_t pn_id; mp_parse_node_t pn_colon; mp_parse_node_t pn_equal; - if (MP_PARSE_NODE_IS_ID(pn)) { + if (pn_kind == -1) { // this parameter is just an id pn_id = pn; pn_colon = MP_PARSE_NODE_NULL; pn_equal = MP_PARSE_NODE_NULL; - } else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_typedargslist_name)) { + } else if (pn_kind == PN_typedargslist_name) { // this parameter has a colon and/or equal specifier mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; @@ -623,7 +630,7 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) pn_equal = pns->nodes[2]; } else { - assert(MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_varargslist_name)); // should be + assert(pn_kind == PN_varargslist_name); // should be // this parameter has an equal specifier mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn; |