diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-11 10:40:38 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-11 10:40:38 +0000 |
commit | a9ddd6d9df97637c944bfc51a66476008a88feb3 (patch) | |
tree | d06620f3a7ad7beba8a2c82d6701bd9ef45ab7ec /py/obj.c | |
parent | 5f3fe3aa149721a08d7c9b1a683ba502f59d1aae (diff) | |
download | micropython-a9ddd6d9df97637c944bfc51a66476008a88feb3.tar.gz micropython-a9ddd6d9df97637c944bfc51a66476008a88feb3.zip |
py: Simplify and improve mp_get_index.
It has (again) a fast path for ints, and a simplified "slow" path for
everything else.
Also simplify the way str indexing is done (now matches tuple and list).
Diffstat (limited to 'py/obj.c')
-rw-r--r-- | py/obj.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -277,12 +277,10 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items) { // is_slice determines whether the index is a slice index uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, bool is_slice) { - int i; - if (MP_OBJ_IS_INT(index)) { - i = mp_obj_int_get_checked(index); - } else if (MP_OBJ_IS_TYPE(index, &mp_type_bool)) { - i = (index == mp_const_true ? 1 : 0); - } else { + machine_int_t i; + if (MP_OBJ_IS_SMALL_INT(index)) { + i = MP_OBJ_SMALL_INT_VALUE(index); + } else if (!mp_obj_get_int_maybe(index, &i)) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "%s indices must be integers, not %s", qstr_str(type->name), mp_obj_get_type_str(index))); } |