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. --- stmhal/can.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'stmhal/can.c') diff --git a/stmhal/can.c b/stmhal/can.c index 28f00c994..b10ecd13d 100644 --- a/stmhal/can.c +++ b/stmhal/can.c @@ -395,12 +395,12 @@ STATIC mp_obj_t pyb_can_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_ } tuple->items[1] = MP_OBJ_NEW_SMALL_INT(rx_msg.RTR); tuple->items[2] = MP_OBJ_NEW_SMALL_INT(rx_msg.FMI); - byte *data; - tuple->items[3] = mp_obj_str_builder_start(&mp_type_bytes, rx_msg.DLC, &data); + vstr_t vstr; + vstr_init_len(&vstr, rx_msg.DLC); for (mp_uint_t i = 0; i < rx_msg.DLC; i++) { - data[i] = rx_msg.Data[i]; // Data is uint32_t but holds only 1 byte + vstr.buf[i] = rx_msg.Data[i]; // Data is uint32_t but holds only 1 byte } - tuple->items[3] = mp_obj_str_builder_end(tuple->items[3]); + tuple->items[3] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); return tuple; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_can_recv_obj, 1, pyb_can_recv); -- cgit v1.2.3