py/objslice: Inline fetching of slice paramters in str_subscr().
To reduce code size.
This commit is contained in:
parent
4c93955b7b
commit
10709846f3
7
py/obj.h
7
py/obj.h
@ -786,7 +786,12 @@ typedef struct {
|
|||||||
} mp_bound_slice_t;
|
} mp_bound_slice_t;
|
||||||
|
|
||||||
// slice
|
// slice
|
||||||
void mp_obj_slice_get(mp_obj_t self_in, mp_obj_t *start, mp_obj_t *stop, mp_obj_t *step);
|
typedef struct _mp_obj_slice_t {
|
||||||
|
mp_obj_base_t base;
|
||||||
|
mp_obj_t start;
|
||||||
|
mp_obj_t stop;
|
||||||
|
mp_obj_t step;
|
||||||
|
} mp_obj_slice_t;
|
||||||
void mp_obj_slice_indices(mp_obj_t self_in, mp_int_t length, mp_bound_slice_t *result);
|
void mp_obj_slice_indices(mp_obj_t self_in, mp_int_t length, mp_bound_slice_t *result);
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
|
@ -34,13 +34,6 @@
|
|||||||
|
|
||||||
#if MICROPY_PY_BUILTINS_SLICE
|
#if MICROPY_PY_BUILTINS_SLICE
|
||||||
|
|
||||||
typedef struct _mp_obj_slice_t {
|
|
||||||
mp_obj_base_t base;
|
|
||||||
mp_obj_t start;
|
|
||||||
mp_obj_t stop;
|
|
||||||
mp_obj_t step;
|
|
||||||
} mp_obj_slice_t;
|
|
||||||
|
|
||||||
STATIC void slice_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
|
STATIC void slice_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
|
||||||
(void)kind;
|
(void)kind;
|
||||||
mp_obj_slice_t *o = MP_OBJ_TO_PTR(o_in);
|
mp_obj_slice_t *o = MP_OBJ_TO_PTR(o_in);
|
||||||
@ -119,14 +112,6 @@ mp_obj_t mp_obj_new_slice(mp_obj_t ostart, mp_obj_t ostop, mp_obj_t ostep) {
|
|||||||
return MP_OBJ_FROM_PTR(o);
|
return MP_OBJ_FROM_PTR(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_obj_slice_get(mp_obj_t self_in, mp_obj_t *start, mp_obj_t *stop, mp_obj_t *step) {
|
|
||||||
assert(mp_obj_is_type(self_in, &mp_type_slice));
|
|
||||||
mp_obj_slice_t *self = MP_OBJ_TO_PTR(self_in);
|
|
||||||
*start = self->start;
|
|
||||||
*stop = self->stop;
|
|
||||||
*step = self->step;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the real index and step values for a slice when applied to a sequence of
|
// Return the real index and step values for a slice when applied to a sequence of
|
||||||
// the given length, resolving missing components, negative values and values off
|
// the given length, resolving missing components, negative values and values off
|
||||||
// the end of the sequence.
|
// the end of the sequence.
|
||||||
|
@ -184,7 +184,11 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
|||||||
#if MICROPY_PY_BUILTINS_SLICE
|
#if MICROPY_PY_BUILTINS_SLICE
|
||||||
if (mp_obj_is_type(index, &mp_type_slice)) {
|
if (mp_obj_is_type(index, &mp_type_slice)) {
|
||||||
mp_obj_t ostart, ostop, ostep;
|
mp_obj_t ostart, ostop, ostep;
|
||||||
mp_obj_slice_get(index, &ostart, &ostop, &ostep);
|
mp_obj_slice_t *slice = MP_OBJ_TO_PTR(index);
|
||||||
|
ostart = slice->start;
|
||||||
|
ostop = slice->stop;
|
||||||
|
ostep = slice->step;
|
||||||
|
|
||||||
if (ostep != mp_const_none && ostep != MP_OBJ_NEW_SMALL_INT(1)) {
|
if (ostep != mp_const_none && ostep != MP_OBJ_NEW_SMALL_INT(1)) {
|
||||||
mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported");
|
mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user