[pypy-commit] pypy list-strategies: added _getitem_unwrapped in RangeListStrategy to avoid wrapping/unwrapping

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


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47492:158c79deb4df
Date: 2011-03-30 15:05 +0200
http://bitbucket.org/pypy/pypy/changeset/158c79deb4df/

Log:	added _getitem_unwrapped in RangeListStrategy to avoid
	wrapping/unwrapping

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
@@ -306,7 +306,7 @@
     def length(self, w_list):
         return self.cast_from_void_star(w_list.lstorage)[2]
 
-    def getitem(self, w_list, i):
+    def _getitem_unwrapped(self, w_list, i):
         v = self.cast_from_void_star(w_list.lstorage)
         start = v[0]
         step = v[1]
@@ -317,7 +317,10 @@
                 raise IndexError
         elif i >= length:
             raise IndexError
-        return self.wrap(start + i * step)
+        return start + i * step
+
+    def getitem(self, w_list, i):
+        return self.wrap(self._getitem_unwrapped(w_list, i))
 
     def getitems(self, w_list):
         return self._getitems_range(w_list, True)
@@ -352,7 +355,7 @@
         old_step = v[1]
         old_length = v[2]
 
-        new_start = self.unwrap(w_list.getitem(start))
+        new_start = self._getitem_unwrapped(w_list, start)
         new_step = old_step * step
         return make_range_list(self.space, new_start, new_step, length)
 
@@ -360,8 +363,8 @@
         if is_W_IntObject(w_item):
             l = self.cast_from_void_star(w_list.lstorage)
             step = l[1]
-            last_in_range = self.getitem(w_list, -1)
-            if self.unwrap(w_item) - step == self.unwrap(last_in_range):
+            last_in_range = self._getitem_unwrapped(w_list, -1)
+            if self.unwrap(w_item) - step == last_in_range:
                 new = self.cast_to_void_star((l[0],l[1],l[2]+1))
                 w_list.lstorage = new
                 return
@@ -420,10 +423,10 @@
 
     def reverse(self, w_list):
         v = self.cast_from_void_star(w_list.lstorage)
-        w_last = w_list.getitem(-1) #XXX wrapped
+        last = self._getitem_unwrapped(w_list, -1)
         length = v[2]
         skip = v[1]
-        new = self.cast_to_void_star((self.unwrap(w_last), -skip, length))
+        new = self.cast_to_void_star((last, -skip, length))
         w_list.lstorage = new
 
 class AbstractUnwrappedStrategy(object):


More information about the pypy-commit mailing list