Author: Armin Rigo <[email protected]>
Branch:
Changeset: r58993:e82d5aab0b89
Date: 2012-11-19 10:01 +0100
http://bitbucket.org/pypy/pypy/changeset/e82d5aab0b89/
Log: Test and 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
@@ -161,10 +161,7 @@
return list(items)
def switch_to_object_strategy(self):
- if self.strategy is self.space.fromcache(EmptyListStrategy):
- list_w = []
- else:
- list_w = self.getitems()
+ list_w = self.getitems()
self.strategy = self.space.fromcache(ObjectListStrategy)
# XXX this is quite indirect
self.init_from_list_w(list_w)
@@ -443,6 +440,9 @@
def sort(self, w_list, reverse):
raise NotImplementedError
+ def is_empty_strategy(self):
+ return False
+
class EmptyListStrategy(ListStrategy):
"""EmptyListStrategy is used when a W_List withouth elements is created.
@@ -579,6 +579,9 @@
def reverse(self, w_list):
pass
+ def is_empty_strategy(self):
+ return True
+
class SizeListStrategy(EmptyListStrategy):
""" Like empty, but when modified it'll preallocate the size to sizehint
"""
@@ -900,7 +903,7 @@
if self.list_is_correct_type(w_other):
l += self.unerase(w_other.lstorage)
return
- elif w_other.strategy is self.space.fromcache(EmptyListStrategy):
+ elif w_other.strategy.is_empty_strategy():
return
w_other = w_other._temporarily_as_objects()
@@ -958,7 +961,7 @@
"assign sequence of size %d to extended slice of size %d",
len2, slicelength)
- if w_other.strategy is self.space.fromcache(EmptyListStrategy):
+ if len2 == 0:
other_items = []
else:
# at this point both w_list and w_other have the same type, so
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
@@ -1268,6 +1268,15 @@
assert ([5] > [N]) is False
assert ([5] >= [N]) is False
+ def test_resizelist_hint(self):
+ import __pypy__
+ l2 = []
+ __pypy__.resizelist_hint(l2, 100)
+ l1 = [1, 2, 3]
+ l1[:] = l2
+ assert len(l1) == 0
+
+
class AppTestForRangeLists(AppTestW_ListObject):
spaceconfig = {"objspace.std.withrangelist": True}
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit