diff options
author | Damien George <damien.p.george@gmail.com> | 2015-01-21 19:14:25 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-01-21 23:17:27 +0000 |
commit | 0b9ee86133a2a0524691c6cdac209dbfcb3bf116 (patch) | |
tree | e17f1f8c26b2d92991a8481ba5d2fc0649a8c6ce /py/modbuiltins.c | |
parent | 2e526ff1a15cfe50aa46fe5611d3160b2a854f49 (diff) |
py: Add mp_obj_new_str_from_vstr, and use it where relevant.
This patch allows to reuse vstr memory when creating str/bytes object.
This improves memory usage.
Also saves code ROM: 128 bytes on stmhal, 92 bytes on bare-arm, and 88
bytes on unix x64.
Diffstat (limited to 'py/modbuiltins.c')
-rw-r--r-- | py/modbuiltins.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/py/modbuiltins.c b/py/modbuiltins.c index b739503ad..68a22934b 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -449,11 +449,10 @@ STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) { MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin___repl_print___obj, mp_builtin___repl_print__); STATIC mp_obj_t mp_builtin_repr(mp_obj_t o_in) { - vstr_t *vstr = vstr_new(); - mp_obj_print_helper((void (*)(void *env, const char *fmt, ...))vstr_printf, vstr, o_in, PRINT_REPR); - mp_obj_t s = mp_obj_new_str(vstr->buf, vstr->len, false); - vstr_free(vstr); - return s; + vstr_t vstr; + vstr_init(&vstr, 16); + mp_obj_print_helper((void (*)(void *env, const char *fmt, ...))vstr_printf, &vstr, o_in, PRINT_REPR); + return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_repr_obj, mp_builtin_repr); |