py, objstr: Optimise bytes subscr when unicode is enabled.

Saves code bytes and makes it faster, so why not?
This commit is contained in:
Damien George 2014-08-11 23:24:29 +01:00
parent 7703d71938
commit 2eb1f604ee
1 changed files with 2 additions and 1 deletions

View File

@ -370,7 +370,8 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
} }
#endif #endif
mp_uint_t index_val = mp_get_index(type, self_len, index, false); mp_uint_t index_val = mp_get_index(type, self_len, index, false);
if (type == &mp_type_bytes) { // If we have unicode enabled the type will always be bytes, so take the short cut.
if (MICROPY_PY_BUILTINS_STR_UNICODE || type == &mp_type_bytes) {
return MP_OBJ_NEW_SMALL_INT(self_data[index_val]); return MP_OBJ_NEW_SMALL_INT(self_data[index_val]);
} else { } else {
return mp_obj_new_str((char*)&self_data[index_val], 1, true); return mp_obj_new_str((char*)&self_data[index_val], 1, true);