diff options
author | Damien George <damien.p.george@gmail.com> | 2014-08-11 23:24:29 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-08-11 23:24:29 +0100 |
commit | 2eb1f604ee3a1b7284ae23581a9c0e2d1e9066a1 (patch) | |
tree | 03f36305ad8402cd9ac6dd5af3ec551758c10756 /py/objstr.c | |
parent | 7703d719380833a5d59fb7ca5087a2d8172b3529 (diff) | |
download | micropython-2eb1f604ee3a1b7284ae23581a9c0e2d1e9066a1.tar.gz micropython-2eb1f604ee3a1b7284ae23581a9c0e2d1e9066a1.zip |
py, objstr: Optimise bytes subscr when unicode is enabled.
Saves code bytes and makes it faster, so why not?
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/py/objstr.c b/py/objstr.c index fb170f83c9..35bb8e749c 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -370,7 +370,8 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } #endif 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]); } else { return mp_obj_new_str((char*)&self_data[index_val], 1, true); |