Skip to content

Commit 5fe1e3c

Browse files
committed
accelerate setitem with slice
When using setitem with a slice and an item that is smaller than the slice, we need to remove items. Until now, this was done with pop, which actually incurred a memory move of the tail of the list for every item being removed. Now that we can mass delete items in the list with `del` and slices, we used that functionality instead.
1 parent 3cb7008 commit 5fe1e3c

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

‎numba/listobject.py‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -677,16 +677,8 @@ def impl_slice(l, index, item):
677677
slice_range.start + len(item))
678678
for i,j in zip(replace_range, item):
679679
l[i] = j
680-
# pop the remaining ones
681-
pop_range = range(slice_range.start + len(item),
682-
slice_range.stop)
683-
# pop will mutate the list, so we always need to pop the
684-
# same index
685-
k = slice_range.start + len(item)
686-
for _ in pop_range:
687-
# FIXME: This may be slow. Each pop can incur a
688-
# memory copy of one or more items.
689-
l.pop(k)
680+
# delete remaining ones
681+
del l[slice_range.start + len(item):slice_range.stop]
690682
# Extended slices
691683
else:
692684
if len(slice_range) != len(item):

0 commit comments

Comments
 (0)