Skip to content

Commit

Permalink
accelerate setitem with slice
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
esc committed Jun 27, 2019
1 parent 3503f9e commit 261dcd1
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions numba/listobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,16 +688,8 @@ def impl_slice(l, index, item):
slice_range.start + len(item))
for i,j in zip(replace_range, item):
l[i] = j
# pop the remaining ones
pop_range = range(slice_range.start + len(item),
slice_range.stop)
# pop will mutate the list, so we always need to pop the
# same index
k = slice_range.start + len(item)
for _ in pop_range:
# FIXME: This may be slow. Each pop can incur a
# memory copy of one or more items.
l.pop(k)
# delete remaining ones
del l[slice_range.start + len(item):slice_range.stop]
# Extended slices
else:
if len(slice_range) != len(item):
Expand Down

0 comments on commit 261dcd1

Please sign in to comment.