8000 py/objstr: When constructing str from bytes, check for existing qstr. · micropython/micropython@8d956c2 · GitHub < 8000 link rel="manifest" href="/manifest.json" crossOrigin="use-credentials">
[go: up one dir, main page]

Skip to content

Commit 8d956c2

Browse files
committed
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.
1 parent 1f1d519 commit 8d956c2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

py/objstr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ mp_obj_t mp_obj_str_make_new(const mp_obj 80B6 _type_t *type, size_t n_args, size_t n_
164164
mp_raise_msg(&mp_type_UnicodeError, NULL);
165165
}
166166
#endif
167+
168+
// Check if a qstr with this data already exists
169+
qstr q = qstr_find_strn((const char*)str_data, str_len);
170+
if (q != MP_QSTR_NULL) {
171+
return MP_OBJ_NEW_QSTR(q);
172+
}
173+
167174
mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_str_copy(type, NULL, str_len));
168175
o->data = str_data;
169176
o->hash = str_hash;

0 commit comments

Comments
 (0)
0