8000 py/objstr: Add a helper to set mp_obj_str_t data. · jimmo/micropython@c44b392 · GitHub
[go: up one dir, main page]

Skip to content

Commit c44b392

Browse files
jimmodpgeorge
authored andcommitted
py/objstr: Add a helper to set mp_obj_str_t data.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent 4fc543c commit c44b392

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

py/objstr.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,12 @@ mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_u
20452045
}
20462046
}
20472047

2048+
void mp_obj_str_set_data(mp_obj_str_t *str, const byte *data, size_t len) {
2049+
str->data = data;
2050+
str->len = len;
2051+
str->hash = qstr_compute_hash(data, len);
2052+
}
2053+
20482054
// This locals table is used for the following types: str, bytes, bytearray, array.array.
20492055
// Each type takes a different section (start to end offset) of this table.
20502056
STATIC const mp_rom_map_elem_t array_bytearray_str_bytes_locals_table[] = {

py/objstr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte *data, siz
9494
mp_obj_t mp_obj_str_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
9595
mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags);
9696

97+
void mp_obj_str_set_data(mp_obj_str_t *str, const byte *data, size_t len);
98+
9799
const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, size_t self_len,
98100
mp_obj_t index, bool is_slice);
99101
const byte *find_subbytes(const byte *haystack, size_t hlen, const byte *needle, size_t nlen, int direction);

0 commit comments

Comments
 (0)
0