summaryrefslogtreecommitdiff
path: root/py/compile.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-11-01 13:16:16 +1100
committerDamien George <damien.p.george@gmail.com>2017-11-01 13:16:16 +1100
commit487dbdb26748b86cf247600af187437310311145 (patch)
tree4b01d33357ced617a5e4af54845174d9e16ef42b /py/compile.c
parentfe45d78b1edd6d2202c3544797885cb0b12d4f03 (diff)
py/compile: Use alloca instead of qstr_build when compiling import name.
The technique of using alloca is how dotted import names are composed in mp_import_from and mp_builtin___import__, so use the same technique in the compiler. This puts less pressure on the heap (only the stack is used if the qstr already exists, and if it doesn't exist then the standard qstr block memory is used for the new qstr rather than a separate chunk of the heap) and reduces overall code size.
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/py/compile.c b/py/compile.c
index 4e704abfb..ee017498a 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -1050,8 +1050,8 @@ STATIC void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) {
for (int i = 0; i < n; i++) {
len += qstr_len(MP_PARSE_NODE_LEAF_ARG(pns->nodes[i]));
}
- byte *q_ptr;
- byte *str_dest = qstr_build_start(len, &q_ptr);
+ char *q_ptr = alloca(len);
+ char *str_dest = q_ptr;
for (int i = 0; i < n; i++) {
if (i > 0) {
*str_dest++ = '.';
@@ -1061,7 +1061,7 @@ STATIC void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) {
memcpy(str_dest, str_src, str_src_len);
str_dest += str_src_len;
}
- qstr q_full = qstr_build_end(q_ptr);
+ qstr q_full = qstr_from_strn(q_ptr, len);
EMIT_ARG(import_name, q_full);
if (is_as) {
for (int i = 1; i < n; i++) {