diff options
author | Damien George <damien.p.george@gmail.com> | 2017-11-16 13:53:04 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-11-16 13:53:04 +1100 |
commit | 1f1d5194d775ad996f1d341c1a44b56af7ea4d4c (patch) | |
tree | 1ec3138b14dfbd7a759bd065991b346a112fe1cb /py/objstr.h | |
parent | 4601759bf59e16b860a3f082e9aa4ea78356bf92 (diff) |
py/objstr: Make mp_obj_new_str_of_type check for existing interned qstr.
The function mp_obj_new_str_of_type is a general str object constructor
used in many places in the code to create either a str or bytes object.
When creating a str it should first check if the string data already exists
as an interned qstr, and if so then return the qstr object. This patch
makes the function have such behaviour, which helps to reduce heap usage by
reusing existing interned data where possible.
The old behaviour of mp_obj_new_str_of_type (which didn't check for
existing interned data) is made available through the function
mp_obj_new_str_copy, but should only be used in very special cases.
One consequence of this patch is that the following expression is now True:
'abc' is ' abc '.split()[0]
Diffstat (limited to 'py/objstr.h')
-rw-r--r-- | py/objstr.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/py/objstr.h b/py/objstr.h index 82501a763..4e55cad09 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -65,6 +65,7 @@ mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t void mp_str_print_json(const mp_print_t *print, const byte *str_data, size_t str_len); mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args); +mp_obj_t mp_obj_new_str_copy(const mp_obj_type_t *type, const byte* data, size_t len); mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte* data, size_t len); mp_obj_t mp_obj_str_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in); |