py: reduce array slice assignment code size
This commit is contained in:
parent
2af846e711
commit
6a388aaa7c
@ -402,37 +402,30 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
|
|||||||
|
|
||||||
// TODO: check src/dst compat
|
// TODO: check src/dst compat
|
||||||
mp_int_t len_adj = src_len - (slice.stop - slice.start);
|
mp_int_t len_adj = src_len - (slice.stop - slice.start);
|
||||||
if (len_adj > 0) {
|
uint8_t* dest_items = o->items;
|
||||||
#if MICROPY_PY_BUILTINS_MEMORYVIEW
|
#if MICROPY_PY_BUILTINS_MEMORYVIEW
|
||||||
if (o->base.type == &mp_type_memoryview) {
|
if (o->base.type == &mp_type_memoryview) {
|
||||||
|
if (len_adj != 0) {
|
||||||
goto compat_error;
|
goto compat_error;
|
||||||
}
|
}
|
||||||
#endif
|
dest_items += o->free * item_sz;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (len_adj > 0) {
|
||||||
if (len_adj > o->free) {
|
if (len_adj > o->free) {
|
||||||
// TODO: alloc policy; at the moment we go conservative
|
// TODO: alloc policy; at the moment we go conservative
|
||||||
o->items = m_renew(byte, o->items, (o->len + o->free) * item_sz, (o->len + len_adj) * item_sz);
|
o->items = m_renew(byte, o->items, (o->len + o->free) * item_sz, (o->len + len_adj) * item_sz);
|
||||||
o->free = 0;
|
o->free = 0;
|
||||||
}
|
}
|
||||||
mp_seq_replace_slice_grow_inplace(o->items, o->len,
|
mp_seq_replace_slice_grow_inplace(dest_items, o->len,
|
||||||
slice.start, slice.stop, src_items, src_len, len_adj, item_sz);
|
slice.start, slice.stop, src_items, src_len, len_adj, item_sz);
|
||||||
} else {
|
} else {
|
||||||
#if MICROPY_PY_BUILTINS_MEMORYVIEW
|
mp_seq_replace_slice_no_grow(dest_items, o->len,
|
||||||
if (o->base.type == &mp_type_memoryview) {
|
slice.start, slice.stop, src_items, src_len, item_sz);
|
||||||
if (len_adj != 0) {
|
// Clear "freed" elements at the end of list
|
||||||
goto compat_error;
|
// TODO: This is actually only needed for typecode=='O'
|
||||||
}
|
mp_seq_clear(dest_items, o->len + len_adj, o->len, item_sz);
|
||||||
mp_seq_replace_slice_no_grow((uint8_t*)o->items + (o->free * item_sz), o->len,
|
// TODO: alloc policy after shrinking
|
||||||
slice.start, slice.stop, src_items, src_len, item_sz);
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
mp_seq_replace_slice_no_grow(o->items, o->len,
|
|
||||||
slice.start, slice.stop, src_items, src_len, item_sz);
|
|
||||||
// Clear "freed" elements at the end of list
|
|
||||||
// TODO: This is actually only needed for typecode=='O'
|
|
||||||
mp_seq_clear(o->items, o->len + len_adj, o->len, item_sz);
|
|
||||||
// TODO: alloc policy after shrinking
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
o->len += len_adj;
|
o->len += len_adj;
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user