summaryrefslogtreecommitdiffstatshomepage
path: root/py/objlist.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-05-10 22:23:00 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-05-10 22:24:31 +0300
commit94d8246272b2df7dbfb70ec85ed06e3b13793bac (patch)
tree391a83a4bfc111060aa515c8cad0a415711422e2 /py/objlist.c
parentd915a52eb650a0809e15e6be25e58a3db7e73025 (diff)
downloadmicropython-94d8246272b2df7dbfb70ec85ed06e3b13793bac.tar.gz
micropython-94d8246272b2df7dbfb70ec85ed06e3b13793bac.zip
objlist: Implement non-growing slice assignment.
Slice value to assign can be only a list so far too.
Diffstat (limited to 'py/objlist.c')
-rw-r--r--py/objlist.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/py/objlist.c b/py/objlist.c
index 08c1716179..4432b2447b 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -173,6 +173,26 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
uint index_val = mp_get_index(self->base.type, self->len, index, false);
return self->items[index_val];
} else {
+#if MICROPY_ENABLE_SLICE
+ if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
+ mp_obj_list_t *self = self_in;
+ assert(MP_OBJ_IS_TYPE(value, &mp_type_list));
+ mp_obj_list_t *slice = value;
+ machine_uint_t start, stop;
+ if (!mp_seq_get_fast_slice_indexes(self->len, index, &start, &stop)) {
+ assert(0);
+ }
+ int len_adj = slice->len - (stop - start);
+ //printf("Len adj: %d\n", len_adj);
+ assert(len_adj <= 0);
+ mp_seq_replace_slice_no_grow(self->items, self->len, start, stop, slice->items, slice->len, mp_obj_t);
+ // Clear "freed" elements at the end of list
+ mp_seq_clear(self->items, self->len + len_adj, self->len, sizeof(*self->items));
+ self->len += len_adj;
+ // TODO: apply allocation policy re: alloc_size
+ return mp_const_none;
+ }
+#endif
mp_obj_list_store(self_in, index, value);
return mp_const_none;
}