From c44b3927b8f464e1e01c07b2431e7db251e6d8c0 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Fri, 7 Oct 2022 11:06:43 +1100 Subject: [PATCH] py/objstr: Add a helper to set mp_obj_str_t data. Signed-off-by: Jim Mussared --- py/objstr.c | 6 ++++++ py/objstr.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/py/objstr.c b/py/objstr.c index 55e737fffc..8c639e7354 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -2045,6 +2045,12 @@ mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_u } } +void mp_obj_str_set_data(mp_obj_str_t *str, const byte *data, size_t len) { + str->data = data; + str->len = len; + str->hash = qstr_compute_hash(data, len); +} + // This locals table is used for the following types: str, bytes, bytearray, array.array. // Each type takes a different section (start to end offset) of this table. STATIC const mp_rom_map_elem_t array_bytearray_str_bytes_locals_table[] = { diff --git a/py/objstr.h b/py/objstr.h index 6c6735bf5e..72fe1cfef0 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -94,6 +94,8 @@ mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte *data, siz mp_obj_t mp_obj_str_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in); mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags); +void mp_obj_str_set_data(mp_obj_str_t *str, const byte *data, size_t len); + const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, size_t self_len, mp_obj_t index, bool is_slice); const byte *find_subbytes(const byte *haystack, size_t hlen, const byte *needle, size_t nlen, int direction);