diff options
author | Damien George <damien.p.george@gmail.com> | 2016-09-02 14:42:53 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-09-02 14:49:50 +1000 |
commit | 5f3bda422a18d49fb282a93968b658c568343b7d (patch) | |
tree | 46ccb6bcbde0e30598b48f8db7be175b80141a69 /py/objstr.c | |
parent | f127bef3e41f25eea6da73a52aab2fdc53be2464 (diff) | |
download | micropython-5f3bda422a18d49fb282a93968b658c568343b7d.tar.gz micropython-5f3bda422a18d49fb282a93968b658c568343b7d.zip |
py: If str/bytes hash is 0 then explicitly compute it.
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c index e83ff7c844..406ccf290a 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -158,6 +158,9 @@ mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ if (MP_OBJ_IS_TYPE(args[0], &mp_type_bytes)) { GET_STR_DATA_LEN(args[0], str_data, str_len); GET_STR_HASH(args[0], str_hash); + if (str_hash == 0) { + str_hash = qstr_compute_hash(str_data, str_len); + } mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_str_of_type(type, NULL, str_len)); o->data = str_data; o->hash = str_hash; @@ -191,6 +194,9 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size } GET_STR_DATA_LEN(args[0], str_data, str_len); GET_STR_HASH(args[0], str_hash); + if (str_hash == 0) { + str_hash = qstr_compute_hash(str_data, str_len); + } mp_obj_str_t *o = MP_OBJ_TO_PTR(mp_obj_new_str_of_type(&mp_type_bytes, NULL, str_len)); o->data = str_data; o->hash = str_hash; |