diff options
author | Damien George <damien.p.george@gmail.com> | 2015-06-25 14:42:13 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-06-25 14:42:13 +0000 |
commit | 59fba2d6ea31c134c9c0b88dc73cd25b236f167c (patch) | |
tree | 58038f6437d92ea5bf7b5395175c8e844e169556 /py/emitnative.c | |
parent | ed570e4b2a0a68e43b191fb0d5b45fb2ec83aca4 (diff) | |
download | micropython-59fba2d6ea31c134c9c0b88dc73cd25b236f167c.tar.gz micropython-59fba2d6ea31c134c9c0b88dc73cd25b236f167c.zip |
py: Remove mp_load_const_bytes and instead load precreated bytes object.
Previous to this patch each time a bytes object was referenced a new
instance (with the same data) was created. With this patch a single
bytes object is created in the compiler and is loaded directly at execute
time as a true constant (similar to loading bignum and float objects).
This saves on allocating RAM and means that bytes objects can now be
used when the memory manager is locked (eg in interrupts).
The MP_BC_LOAD_CONST_BYTES bytecode was removed as part of this.
Generated bytecode is slightly larger due to storing a pointer to the
bytes object instead of the qstr identifier.
Code size is reduced by about 60 bytes on Thumb2 architectures.
Diffstat (limited to 'py/emitnative.c')
-rw-r--r-- | py/emitnative.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/py/emitnative.c b/py/emitnative.c index 974b8fc7b5..0d3f78da4e 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -167,7 +167,6 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = { [MP_F_CONVERT_OBJ_TO_NATIVE] = 2, [MP_F_CONVERT_NATIVE_TO_OBJ] = 2, - [MP_F_LOAD_CONST_BYTES] = 1, [MP_F_LOAD_NAME] = 1, [MP_F_LOAD_GLOBAL] = 1, [MP_F_LOAD_BUILD_CLASS] = 0, @@ -1295,7 +1294,7 @@ STATIC void emit_native_load_const_small_int(emit_t *emit, mp_int_t arg) { } } -STATIC void emit_native_load_const_str(emit_t *emit, qstr qst, bool bytes) { +STATIC void emit_native_load_const_str(emit_t *emit, qstr qst) { emit_native_pre(emit); // TODO: Eventually we want to be able to work with raw pointers in viper to // do native array access. For now we just load them as any other object. @@ -1308,12 +1307,7 @@ STATIC void emit_native_load_const_str(emit_t *emit, qstr qst, bool bytes) { } else */ { - if (bytes) { - emit_call_with_imm_arg(emit, MP_F_LOAD_CONST_BYTES, qst, REG_ARG_1); - emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); - } else { - emit_post_push_imm(emit, VTYPE_PYOBJ, (mp_uint_t)MP_OBJ_NEW_QSTR(qst)); - } + emit_post_push_imm(emit, VTYPE_PYOBJ, (mp_uint_t)MP_OBJ_NEW_QSTR(qst)); } } |