[pypy-commit] pypy list-strategies: do not revert to EmptyListStrategy anymore

l.diekmann noreply at buildbot.pypy.org
Fri Sep 23 13:14:55 CEST 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47526:4d38656df53a
Date: 2011-08-30 11:51 +0200
http://bitbucket.org/pypy/pypy/changeset/4d38656df53a/

Log:	do not revert to EmptyListStrategy anymore

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
@@ -87,11 +87,6 @@
         strategy = self.strategy = self.space.fromcache(ObjectListStrategy)
         strategy.init_from_list_w(self, list_w)
 
-    def check_empty_strategy(self):
-        if self.length() == 0:
-            self.strategy = self.space.fromcache(EmptyListStrategy)
-            self.strategy.init_from_list_w(self, self.strategy.emptylist)
-
     def clone(self):
         return self.strategy.clone(self)
 
@@ -439,7 +434,6 @@
             else:
                 new = self.cast_to_void_star((l[0],l[1],l[2]-1))
             w_list.lstorage = new
-            w_list.check_empty_strategy()
             return r
 
         self.switch_to_integer_strategy(w_list)
@@ -657,15 +651,12 @@
             items[start] = other_items[i]
             start += step
 
-        w_list.check_empty_strategy()
-
     def deleteitem(self, w_list, index):
         l = self.cast_from_void_star(w_list.lstorage)
         try:
             del l[index]
         except IndexError:
             raise
-        w_list.check_empty_strategy()
 
     def deleteslice(self, w_list, start, step, slicelength):
         items = self.cast_from_void_star(w_list.lstorage)
@@ -699,8 +690,6 @@
             assert start >= 0 # annotator hint
             del items[start:]
 
-        w_list.check_empty_strategy()
-
     def pop(self, w_list, index):
         l = self.cast_from_void_star(w_list.lstorage)
         # not sure if RPython raises IndexError on pop
@@ -711,12 +700,9 @@
             raise
 
         w_item = self.wrap(item)
-
-        w_list.check_empty_strategy()
         return w_item
 
     def mul(self, w_list, times):
-        # clone 
         w_newlist = w_list.clone()
         w_newlist.inplace_mul(times)
         return w_newlist
@@ -939,8 +925,8 @@
     if w_list1.length() != w_list2.length():
         return space.w_False
 
-    #XXX fast path with strategies: not equal => False (except one is ObjectStr)
     i = 0
+                                   # is this necessary?
     while i < w_list1.length() and i < w_list2.length():
         if not space.eq_w(w_list1.getitem(i), w_list2.getitem(i)):
             return space.w_False
diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -92,7 +92,7 @@
         l.insert(0, self.space.wrap(2))
         assert isinstance(l.strategy, IntegerListStrategy)
 
-    def test_list_empty_after_delete(self):
+    def notest_list_empty_after_delete(self):
         l = W_ListObject(self.space, [self.space.wrap(3)])
         assert isinstance(l.strategy, IntegerListStrategy)
         l.deleteitem(0)
@@ -165,7 +165,7 @@
         l = W_ListObject(self.space, wrapitems(["a",3,"c",4,"e"]))
         other = W_ListObject(self.space, [])
         keep_other_strategy(l, 0, 1, l.length(), other)
-        assert l.strategy is self.space.fromcache(EmptyListStrategy)
+        assert l.strategy is self.space.fromcache(ObjectListStrategy)
 
     def test_empty_setslice_with_objectlist(self):
         l = W_ListObject(self.space, [])
@@ -266,12 +266,11 @@
         assert isinstance(l.strategy, EmptyListStrategy)
 
         l = make_range_list(self.space, 1, 1, 10)
-        print l.getitems()
         for i in l.getitems():
             assert isinstance(l.strategy, RangeListStrategy)
             l.pop(l.length()-1)
 
-        assert isinstance(l.strategy, EmptyListStrategy)
+        assert isinstance(l.strategy, RangeListStrategy)
 
     def test_range_setslice(self):
         l = make_range_list(self.space, 1, 3, 5)


More information about the pypy-commit mailing list