@@ -139,14 +139,27 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
139139 return MP_OBJ_NOT_SUPPORTED ;
140140 } else {
141141 mp_obj_array_t * o = self_in ;
142- uint index = mp_get_index (o -> base .type , o -> len , index_in , false);
143- if (value == MP_OBJ_SENTINEL ) {
144- // load
145- return mp_binary_get_val_array (o -> typecode , o -> items , index );
142+ if (MP_OBJ_IS_TYPE (index_in , & mp_type_slice )) {
143+ machine_uint_t start , stop ;
144+ if (!m_seq_get_fast_slice_indexes (o -> len , index_in , & start , & stop )) {
145+ assert (0 );
146+ }
147+ mp_obj_array_t * res = array_new (o -> typecode , stop - start );
148+ int sz = mp_binary_get_size ('@' , o -> typecode , NULL );
149+ assert (sz > 0 );
150+ byte * p = o -> items ;
151+ memcpy (res -> items , p + start * sz , (stop - start ) * sz );
152+ return res ;
146153 } else {
147- // store
148- mp_binary_set_val_array (o -> typecode , o -> items , index , value );
149- return mp_const_none ;
154+ uint index = mp_get_index (o -> base .type , o -> len , index_in , false);
155+ if (value == MP_OBJ_SENTINEL ) {
156+ // load
157+ return mp_binary_get_val_array (o -> typecode , o -> items , index );
158+ } else {
159+ // store
160+ mp_binary_set_val_array (o -> typecode , o -> items , index , value );
161+ return mp_const_none ;
162+ }
150163 }
151164 }
152165}
0 commit comments