From 05005f679e00241e15a87751d89327f2c4630cb6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 21 Jan 2015 22:48:37 +0000 Subject: py: Remove mp_obj_str_builder and use vstr instead. With this patch str/bytes construction is streamlined. Always use a vstr to build a str/bytes object. If the size is known beforehand then use vstr_init_len to allocate only required memory. Otherwise use vstr_init and the vstr will grow as needed. Then use mp_obj_new_str_from_vstr to create a str/bytes object using the vstr memory. Saves code ROM: 68 bytes on stmhal, 108 bytes on bare-arm, and 336 bytes on unix x64. --- py/objint.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'py/objint.c') diff --git a/py/objint.c b/py/objint.c index 049d0410e..e8d86ad7e 100644 --- a/py/objint.c +++ b/py/objint.c @@ -340,8 +340,9 @@ STATIC mp_obj_t int_to_bytes(mp_uint_t n_args, const mp_obj_t *args) { mp_int_t val = mp_obj_int_get_checked(args[0]); mp_uint_t len = MP_OBJ_SMALL_INT_VALUE(args[1]); - byte *data; - mp_obj_t o = mp_obj_str_builder_start(&mp_type_bytes, len, &data); + vstr_t vstr; + vstr_init_len(&vstr, len); + byte *data = (byte*)vstr.buf; memset(data, 0, len); if (MP_ENDIANNESS_LITTLE) { @@ -353,7 +354,7 @@ STATIC mp_obj_t int_to_bytes(mp_uint_t n_args, const mp_obj_t *args) { } } - return mp_obj_str_builder_end(o); + return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 2, 4, int_to_bytes); -- cgit v1.2.3