Skip to content

Commit 2eb1f60

Browse files
committed
py, objstr: Optimise bytes subscr when unicode is enabled.
Saves code bytes and makes it faster, so why not?
1 parent 7703d71 commit 2eb1f60

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

py/objstr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
370370
}
371371
#endif
372372
mp_uint_t index_val = mp_get_index(type, self_len, index, false);
373-
if (type == &mp_type_bytes) {
373+
// If we have unicode enabled the type will always be bytes, so take the short cut.
374+
if (MICROPY_PY_BUILTINS_STR_UNICODE || type == &mp_type_bytes) {
374375
return MP_OBJ_NEW_SMALL_INT(self_data[index_val]);
375376
} else {
376377
return mp_obj_new_str((char*)&self_data[index_val], 1, true);

0 commit comments

Comments
 (0)