summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/usb.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-01-21 22:48:37 +0000
committerDamien George <damien.p.george@gmail.com>2015-01-21 23:18:02 +0000
commit05005f679e00241e15a87751d89327f2c4630cb6 (patch)
tree50319ab1dee5af8016e95e3c80a3b28346cdca21 /stmhal/usb.c
parent0b9ee86133a2a0524691c6cdac209dbfcb3bf116 (diff)
downloadmicropython-05005f679e00241e15a87751d89327f2c4630cb6.tar.gz
micropython-05005f679e00241e15a87751d89327f2c4630cb6.zip
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.
Diffstat (limited to 'stmhal/usb.c')
-rw-r--r--stmhal/usb.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/stmhal/usb.c b/stmhal/usb.c
index 0bda0aaeb2..8ea5fb561c 100644
--- a/stmhal/usb.c
+++ b/stmhal/usb.c
@@ -232,17 +232,17 @@ STATIC mp_obj_t pyb_usb_vcp_recv(mp_uint_t n_args, const mp_obj_t *args, mp_map_
mp_arg_parse_all(n_args - 1, args + 1, kw_args, PYB_USB_VCP_SEND_NUM_ARGS, pyb_usb_vcp_send_args, vals);
// get the buffer to receive into
- mp_buffer_info_t bufinfo;
- mp_obj_t o_ret = pyb_buf_get_for_recv(vals[0].u_obj, &bufinfo);
+ vstr_t vstr;
+ mp_obj_t o_ret = pyb_buf_get_for_recv(vals[0].u_obj, &vstr);
// receive the data
- int ret = USBD_CDC_Rx(bufinfo.buf, bufinfo.len, vals[1].u_int);
+ int ret = USBD_CDC_Rx((uint8_t*)vstr.buf, vstr.len, vals[1].u_int);
// return the received data
- if (o_ret == MP_OBJ_NULL) {
+ if (o_ret != MP_OBJ_NULL) {
return mp_obj_new_int(ret); // number of bytes read into given buffer
} else {
- return mp_obj_str_builder_end_with_len(o_ret, ret); // create a new buffer
+ return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); // create a new buffer
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_usb_vcp_recv_obj, 1, pyb_usb_vcp_recv);