[pypy-commit] pypy default: Issue #2750
arigo
pypy.commits at gmail.com
Sun Feb 11 14:52:39 EST 2018
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r93803:7eaba44b228a
Date: 2018-02-11 20:52 +0100
http://bitbucket.org/pypy/pypy/changeset/7eaba44b228a/
Log: Issue #2750
Speed up array.__setslice__() for arguments that are changing the
size of the array, but in such a way that it's just an
array.extend().
diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -1090,12 +1090,16 @@
start, stop, step, size = self.space.decode_index4(w_idx, self.len)
assert step != 0
if w_item.len != size or self is w_item:
- # XXX this is a giant slow hack
- w_lst = self.descr_tolist(space)
- w_item = space.call_method(w_item, 'tolist')
- space.setitem(w_lst, w_idx, w_item)
- self.setlen(0)
- self.fromsequence(w_lst)
+ if start == self.len and step > 0:
+ # we actually want simply extend()
+ self.extend(w_item)
+ else:
+ # XXX this is a giant slow hack
+ w_lst = self.descr_tolist(space)
+ w_item = space.call_method(w_item, 'tolist')
+ space.setitem(w_lst, w_idx, w_item)
+ self.setlen(0)
+ self.fromsequence(w_lst)
else:
j = 0
buf = self.get_buffer()
diff --git a/pypy/module/array/test/test_array.py b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -267,6 +267,12 @@
b = self.array('u', u'hi')
assert len(b) == 2 and b[0] == 'h' and b[1] == 'i'
+ def test_setslice_to_extend(self):
+ a = self.array('i')
+ a[0:1] = self.array('i', [9])
+ a[1:5] = self.array('i', [99])
+ assert list(a) == [9, 99]
+
def test_sequence(self):
a = self.array('i', [1, 2, 3, 4])
assert len(a) == 4
More information about the pypy-commit
mailing list