Author: Armin Rigo <[email protected]>
Branch:
Changeset: r51564:5c3a4d558079
Date: 2012-01-21 11:18 +0100
http://bitbucket.org/pypy/pypy/changeset/5c3a4d558079/
Log: lists have the same performance issue as bytearray objects. Fix.
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -804,10 +804,11 @@
while i >= lim:
items[i] = items[i-delta]
i -= 1
- elif start >= 0:
+ elif delta == 0:
+ pass
+ else:
+ assert start >= 0 # start<0 is only possible with
slicelength==0
del items[start:start+delta]
- else:
- assert delta==0 # start<0 is only possible with
slicelength==0
elif len2 != slicelength: # No resize for extended slices
raise operationerrfmt(self.space.w_ValueError, "attempt to "
"assign sequence of size %d to extended slice of size %d",
@@ -851,8 +852,8 @@
if step == 1:
assert start >= 0
- assert slicelength >= 0
- del items[start:start+slicelength]
+ if slicelength > 0:
+ del items[start:start+slicelength]
else:
n = len(items)
i = start
diff --git a/pypy/objspace/std/test/test_listobject.py
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -397,6 +397,7 @@
on_cpython = (option.runappdirect and
not hasattr(sys, 'pypy_translation_info'))
cls.w_on_cpython = cls.space.wrap(on_cpython)
+ cls.w_runappdirect = cls.space.wrap(option.runappdirect)
def test_getstrategyfromlist_w(self):
l0 = ["a", "2", "a", True]
@@ -898,6 +899,18 @@
l[::-1] = l
assert l == [6,5,4,3,2,1]
+ def test_setitem_slice_performance(self):
+ # because of a complexity bug, this used to take forever on a
+ # translated pypy. On CPython2.6 -A, it takes around 5 seconds.
+ if self.runappdirect:
+ count = 16*1024*1024
+ else:
+ count = 1024
+ b = [None] * count
+ for i in range(count):
+ b[i:i+1] = ['y']
+ assert b == ['y'] * count
+
def test_recursive_repr(self):
l = []
assert repr(l) == '[]'
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit