[pypy-commit] pypy list-strategies: cache empty list

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


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47519:950eee3996c9
Date: 2011-07-29 12:33 +0200
http://bitbucket.org/pypy/pypy/changeset/950eee3996c9/

Log:	cache empty list

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
@@ -37,7 +37,6 @@
             return space.fromcache(IntegerListStrategy)
 
     # check for strings
-    #if all(is_W_StringObject(e) for e in list_w)
     it = iter(list_w)
     while(True):
         try:
@@ -91,7 +90,7 @@
     def check_empty_strategy(self):
         if self.length() == 0:
             self.strategy = self.space.fromcache(EmptyListStrategy)
-            self.strategy.init_from_list_w(self, [])
+            self.strategy.init_from_list_w(self, self.strategy.emptylist)
 
     def clone(self):
         return self.strategy.clone(self)
@@ -229,6 +228,10 @@
 
 class EmptyListStrategy(ListStrategy):
 
+    def __init__(self, space):
+        ListStrategy.__init__(self, space)
+        self.emptylist = []
+
     def init_from_list_w(self, w_list, list_w):
         assert len(list_w) == 0
         w_list.lstorage = self.cast_to_void_star(None)
@@ -250,17 +253,16 @@
         raise IndexError
 
     def getslice(self, w_list, start, stop, step, length):
-        return W_ListObject(self.space, [])
+        return W_ListObject(self.space, self.emptylist)
 
     def getitems(self, w_list):
-        # cache result XXX
-        return []
+        return self.emptylist
 
     def getitems_copy(self, w_list):
-        return []
+        return self.emptylist
 
     def getstorage_copy(self, w_list):
-        return self.cast_to_void_star([])
+        return self.cast_to_void_star(self.emptylist)
 
     def append(self, w_list, w_item):
         w_list.__init__(self.space, [w_item])


More information about the pypy-commit mailing list