summaryrefslogtreecommitdiff
path: root/py/objlist.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-10 06:37:11 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-10 07:13:32 +0200
commit0cd1dc06e673e86058eb14cdd7ae6622cb57fde5 (patch)
tree0a40e8da4e193922c108daaeb9f8dbd4a8beca4b /py/objlist.c
parent76f06de96dbdc4274eb059efe1ce2020f9921835 (diff)
Factor out mp_seq_index_obj() function to implement .index() on sequences.
Diffstat (limited to 'py/objlist.c')
-rw-r--r--py/objlist.c19
1 files changed, 1 insertions, 18 deletions
diff --git a/py/objlist.c b/py/objlist.c
index 9f20acbd4..0c6525be8 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -274,24 +274,7 @@ static mp_obj_t list_index(uint n_args, const mp_obj_t *args) {
assert(2 <= n_args && n_args <= 4);
assert(MP_OBJ_IS_TYPE(args[0], &list_type));
mp_obj_list_t *self = args[0];
- mp_obj_t *value = args[1];
- uint start = 0;
- uint stop = self->len;
-
- if (n_args >= 3) {
- start = mp_get_index(self->base.type, self->len, args[2]);
- if (n_args >= 4) {
- stop = mp_get_index(self->base.type, self->len, args[3]);
- }
- }
-
- for (uint i = start; i < stop; i++) {
- if (mp_obj_equal(self->items[i], value)) {
- return mp_obj_new_int(i);
- }
- }
-
- nlr_jump(mp_obj_new_exception_msg(MP_QSTR_ValueError, "object not in list"));
+ return mp_seq_index_obj(self->items, self->len, n_args, args);
}
static mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) {