aboutsummaryrefslogtreecommitdiff
path: root/py/objstr.c
diff options
context:
space:
mode:
authorDamien George2017-11-16 14:02:28 +1100
committerDamien George2017-11-16 14:02:28 +1100
commit8d956c26d150749375115346f4ca319455107587 (patch)
tree51ab2de6a2267e1df334727af9cb216ddfe99e56 /py/objstr.c
parent1f1d5194d775ad996f1d341c1a44b56af7ea4d4c (diff)
py/objstr: When constructing str from bytes, check for existing qstr.
This patch uses existing qstr data where possible when constructing a str from a bytes object.
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c
index bca2af801..1ff5132d2 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -164,6 +164,13 @@ mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
mp_raise_msg(&mp_type_UnicodeError, NULL);
}
#endif
+
+ // Check if a qstr with this data already exists
+ qstr q = qstr_find_strn((const char*)str_data, str_len);
+ if (q != MP_QSTR_NULL) {
+ return MP_OBJ_NEW_QSTR(q);
+ }
+
mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_str_copy(type, NULL, str_len));
o->data = str_data;
o->hash = str_hash;