remove unnecessary intermediate mp_obj_subscr wrapper

This commit is contained in:
Roy Hooper 2019-11-26 18:39:08 -05:00
parent 0b0aa5c5cf
commit 56720eae0a
10 changed files with 11 additions and 16 deletions

View File

@ -150,7 +150,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_urandom_randint_obj, mod_urandom_randint);
STATIC mp_obj_t mod_urandom_choice(mp_obj_t seq) {
mp_int_t len = mp_obj_get_int(mp_obj_len(seq));
if (len > 0) {
return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow(len)), MP_OBJ_SENTINEL);
return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow(len)), MP_OBJ_SENTINEL, seq);
} else {
nlr_raise(mp_obj_new_exception(&mp_type_IndexError));
}

View File

@ -373,7 +373,7 @@ mp_obj_t mp_vfs_listdir(size_t n_args, const mp_obj_t *args) {
mp_obj_t dir_list = mp_obj_new_list(0, NULL);
mp_obj_t next;
while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
mp_obj_list_append(dir_list, mp_obj_subscr(next, MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_SENTINEL));
mp_obj_list_append(dir_list, mp_obj_subscr(next, MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_SENTINEL, next));
}
return dir_list;
}

View File

@ -311,7 +311,7 @@ STATIC mp_obj_t jobject_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
// TODO: subscr_load_adaptor & subscr_getiter convenience functions
// should be moved to common location for reuse.
STATIC mp_obj_t subscr_load_adaptor(mp_obj_t self_in, mp_obj_t index_in) {
return mp_obj_subscr(self_in, index_in, MP_OBJ_SENTINEL);
return mp_obj_subscr(self_in, index_in, MP_OBJ_SENTINEL, self_in);
}
MP_DEFINE_CONST_FUN_OBJ_2(subscr_load_adaptor_obj, subscr_load_adaptor);

View File

@ -487,11 +487,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
}
}
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
return mp_obj_subscr_impl(base, index, value, base);
}
mp_obj_t mp_obj_subscr_impl(mp_obj_t base, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value, mp_obj_t instance) {
mp_obj_type_t *type = mp_obj_get_type(base);
if (type->subscr != NULL) {

View File

@ -707,8 +707,7 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
mp_obj_t mp_obj_id(mp_obj_t o_in);
mp_obj_t mp_obj_len(mp_obj_t o_in);
mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val);
mp_obj_t mp_obj_subscr_impl(mp_obj_t base, mp_obj_t index, mp_obj_t val, mp_obj_t instance);
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val, mp_obj_t instance);
mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in);
// cell

View File

@ -66,7 +66,7 @@ STATIC mp_obj_t reversed_iternext(mp_obj_t self_in) {
// pre-decrement and index sequence
self->cur_index -= 1;
return mp_obj_subscr(self->seq, MP_OBJ_NEW_SMALL_INT(self->cur_index), MP_OBJ_SENTINEL);
return mp_obj_subscr(self->seq, MP_OBJ_NEW_SMALL_INT(self->cur_index), MP_OBJ_SENTINEL, self->seq);
}
const mp_obj_type_t mp_type_reversed = {

View File

@ -852,7 +852,7 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
meth_args = 3;
}
if (member[0] == MP_OBJ_SENTINEL) {
return mp_obj_subscr_impl(self->subobj[0], index, value, instance);
return mp_obj_subscr(self->subobj[0], index, value, instance);
} else if (member[0] != MP_OBJ_NULL) {
mp_obj_t args[3] = {self_in, index, value};
// TODO probably need to call mp_convert_member_lookup, and use mp_call_method_n_kw

View File

@ -386,7 +386,7 @@ dispatch_loop:
ENTRY(MP_BC_LOAD_SUBSCR): {
MARK_EXC_IP_SELECTIVE();
mp_obj_t index = POP();
SET_TOP(mp_obj_subscr(TOP(), index, MP_OBJ_SENTINEL));
SET_TOP(mp_obj_subscr(TOP(), index, MP_OBJ_SENTINEL, TOP()));
DISPATCH();
}
@ -464,7 +464,7 @@ dispatch_loop:
ENTRY(MP_BC_STORE_SUBSCR):
MARK_EXC_IP_SELECTIVE();
mp_obj_subscr(sp[-1], sp[0], sp[-2]);
mp_obj_subscr(sp[-1], sp[0], sp[-2], sp[-1]);
sp -= 3;
DISPATCH();

View File

@ -145,7 +145,7 @@ STATIC mp_obj_t random_choice(mp_obj_t seq) {
if (len == 0) {
mp_raise_IndexError(translate("empty sequence"));
}
return mp_obj_subscr(seq, mp_obj_new_int(shared_modules_random_randrange(0, len, 1)), MP_OBJ_SENTINEL);
return mp_obj_subscr(seq, mp_obj_new_int(shared_modules_random_randrange(0, len, 1)), MP_OBJ_SENTINEL, seq);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(random_choice_obj, random_choice);

View File

@ -127,7 +127,7 @@ mp_obj_t common_hal_os_listdir(const char* path) {
mp_obj_t next;
while ((next = mp_iternext(iter_obj)) != MP_OBJ_STOP_ITERATION) {
// next[0] is the filename.
mp_obj_list_append(dir_list, mp_obj_subscr(next, MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_SENTINEL));
mp_obj_list_append(dir_list, mp_obj_subscr(next, MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_SENTINEL, dir_list));
RUN_BACKGROUND_TASKS;
}
return dir_list;