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.
This commit is contained in:
Damien George
2015-01-21 19:14:25 +00:00
parent 2e526ff1a1
commit 0b9ee86133
8 changed files with 82 additions and 109 deletions

View File

@@ -400,6 +400,7 @@ mp_obj_t mp_obj_new_int_from_str_len(const char **str, mp_uint_t len, bool neg,
mp_obj_t mp_obj_new_int_from_ll(long long val); // this must return a multi-precision integer object (or raise an overflow exception)
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val); // this must return a multi-precision integer object (or raise an overflow exception)
mp_obj_t mp_obj_new_str(const char* data, mp_uint_t len, bool make_qstr_if_not_already);
mp_obj_t mp_obj_new_str_from_vstr(const mp_obj_type_t *type, vstr_t *vstr);
mp_obj_t mp_obj_new_bytes(const byte* data, mp_uint_t len);
mp_obj_t mp_obj_new_bytearray(mp_uint_t n, void *items);
mp_obj_t mp_obj_new_bytearray_by_ref(mp_uint_t n, void *items);