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/objexcept.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/objexcept.c')
-rw-r--r-- | py/objexcept.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/py/objexcept.c b/py/objexcept.c index e872db341..f2f4012bc 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -351,13 +351,13 @@ mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char } else { // render exception message and store as .args[0] // TODO: optimize bufferbloat - vstr_t *vstr = vstr_new(); + vstr_t vstr; + vstr_init(&vstr, 16); va_list ap; va_start(ap, fmt); - vstr_vprintf(vstr, fmt, ap); + vstr_vprintf(&vstr, fmt, ap); va_end(ap); - o->args->items[0] = mp_obj_new_str(vstr->buf, vstr->len, false); - vstr_free(vstr); + o->args->items[0] = mp_obj_new_str_from_vstr(&mp_type_str, &vstr); } } |