Skip to content

Commit 56720ea

Browse files
committed
remove unnecessary intermediate mp_obj_subscr wrapper
1 parent 0b0aa5c commit 56720ea

10 files changed

Lines changed: 11 additions & 16 deletions

File tree

extmod/modurandom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_urandom_randint_obj, mod_urandom_randint);
150150
STATIC mp_obj_t mod_urandom_choice(mp_obj_t seq) {
151151
mp_int_t len = mp_obj_get_int(mp_obj_len(seq));
152152
if (len > 0) {
153-
return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow(len)), MP_OBJ_SENTINEL);
153+
return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow(len)), MP_OBJ_SENTINEL, seq);
154154
} else {
155155
nlr_raise(mp_obj_new_exception(&mp_type_IndexError));
156156
}

extmod/vfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ mp_obj_t mp_vfs_listdir(size_t n_args, const mp_obj_t *args) {
373373
mp_obj_t dir_list = mp_obj_new_list(0, NULL);
374374
mp_obj_t next;
375375
while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
376-
mp_obj_list_append(dir_list, mp_obj_subscr(next, MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_SENTINEL));
376+
mp_obj_list_append(dir_list, mp_obj_subscr(next, MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_SENTINEL, next));
377377
}
378378
return dir_list;
379379
}

ports/unix/modjni.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ STATIC mp_obj_t jobject_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
311311
// TODO: subscr_load_adaptor & subscr_getiter convenience functions
312312
// should be moved to common location for reuse.
313313
STATIC mp_obj_t subscr_load_adaptor(mp_obj_t self_in, mp_obj_t index_in) {
314-
return mp_obj_subscr(self_in, index_in, MP_OBJ_SENTINEL);
314+
return mp_obj_subscr(self_in, index_in, MP_OBJ_SENTINEL, self_in);
315315
}
316316
MP_DEFINE_CONST_FUN_OBJ_2(subscr_load_adaptor_obj, subscr_load_adaptor);
317317

py/obj.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
487487
}
488488
}
489489

490-
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
491-
return mp_obj_subscr_impl(base, index, value, base);
492-
}
493-
494-
mp_obj_t mp_obj_subscr_impl(mp_obj_t base, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
490+
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
495491
mp_obj_type_t *type = mp_obj_get_type(base);
496492

497493
if (type->subscr != NULL) {

py/obj.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,7 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
707707
mp_obj_t mp_obj_id(mp_obj_t o_in);
708708
mp_obj_t mp_obj_len(mp_obj_t o_in);
709709
mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL
710-
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val);
711-
mp_obj_t mp_obj_subscr_impl(mp_obj_t base, mp_obj_t index, mp_obj_t val, mp_obj_t instance);
710+
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val, mp_obj_t instance);
712711
mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in);
713712

714713
// cell

py/objreversed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ STATIC mp_obj_t reversed_iternext(mp_obj_t self_in) {
6666

6767
// pre-decrement and index sequence
6868
self->cur_index -= 1;
69-
return mp_obj_subscr(self->seq, MP_OBJ_NEW_SMALL_INT(self->cur_index), MP_OBJ_SENTINEL);
69+
return mp_obj_subscr(self->seq, MP_OBJ_NEW_SMALL_INT(self->cur_index), MP_OBJ_SENTINEL, self->seq);
7070
}
7171

7272
const mp_obj_type_t mp_type_reversed = {

py/objtype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
852852
meth_args = 3;
853853
}
854854
if (member[0] == MP_OBJ_SENTINEL) {
855-
return mp_obj_subscr_impl(self->subobj[0], index, value, instance);
855+
return mp_obj_subscr(self->subobj[0], index, value, instance);
856856
} else if (member[0] != MP_OBJ_NULL) {
857857
mp_obj_t args[3] = {self_in, index, value};
858858
// TODO probably need to call mp_convert_member_lookup, and use mp_call_method_n_kw

py/vm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ run_code_state: ;
386386
ENTRY(MP_BC_LOAD_SUBSCR): {
387387
MARK_EXC_IP_SELECTIVE();
388388
mp_obj_t index = POP();
389-
SET_TOP(mp_obj_subscr(TOP(), index, MP_OBJ_SENTINEL));
389+
SET_TOP(mp_obj_subscr(TOP(), index, MP_OBJ_SENTINEL, TOP()));
390390
DISPATCH();
391391
}
392392

@@ -464,7 +464,7 @@ run_code_state: ;
464464

465465
ENTRY(MP_BC_STORE_SUBSCR):
466466
MARK_EXC_IP_SELECTIVE();
467-
mp_obj_subscr(sp[-1], sp[0], sp[-2]);
467+
mp_obj_subscr(sp[-1], sp[0], sp[-2], sp[-1]);
468468
sp -= 3;
469469
DISPATCH();
470470

shared-bindings/random/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ STATIC mp_obj_t random_choice(mp_obj_t seq) {
145145
if (len == 0) {
146146
mp_raise_IndexError(translate("empty sequence"));
147147
}
148-
return mp_obj_subscr(seq, mp_obj_new_int(shared_modules_random_randrange(0, len, 1)), MP_OBJ_SENTINEL);
148+
return mp_obj_subscr(seq, mp_obj_new_int(shared_modules_random_randrange(0, len, 1)), MP_OBJ_SENTINEL, seq);
149149
}
150150
STATIC MP_DEFINE_CONST_FUN_OBJ_1(random_choice_obj, random_choice);
151151

shared-module/os/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ mp_obj_t common_hal_os_listdir(const char* path) {
127127
mp_obj_t next;
128128
while ((next = mp_iternext(iter_obj)) != MP_OBJ_STOP_ITERATION) {
129129
// next[0] is the filename.
130-
mp_obj_list_append(dir_list, mp_obj_subscr(next, MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_SENTINEL));
130+
mp_obj_list_append(dir_list, mp_obj_subscr(next, MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_SENTINEL, dir_list));
131131
RUN_BACKGROUND_TASKS;
132132
}
133133
return dir_list;

0 commit comments

Comments
 (0)