Author: Lukas Diekmann <lukas.diekm...@uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47544:97c5d22ac674
Date: 2011-09-13 14:13 +0200
http://bitbucket.org/pypy/pypy/changeset/97c5d22ac674/

Log:    made RangeList.pop more readable

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
@@ -446,19 +446,22 @@
 
     def pop(self, w_list, index):
         l = self.unerase(w_list.lstorage)
-        # XXX this is silly: the first if checks whether index == 0 or index
-        # =..., then you do almost the same thing again.
-        if index in [0, self.length(w_list)-1]:
+        start = l[0]
+        step = l[1]
+        length = l[2]
+        if index == 0:
             r = self.getitem(w_list, index)
-            if index == 0:
-                new = self.erase((l[0]+l[1],l[1],l[2]-1))
-            else:
-                new = self.erase((l[0],l[1],l[2]-1))
+            new = self.erase((start + step, step, length - 1))
             w_list.lstorage = new
             return r
-
-        self.switch_to_integer_strategy(w_list)
-        return w_list.pop(index)
+        elif index == length - 1:
+            r = self.getitem(w_list, index)
+            new = self.erase((start, step, length - 1))
+            w_list.lstorage = new
+            return r
+        else:
+            self.switch_to_integer_strategy(w_list)
+            return w_list.pop(index)
 
     def setitem(self, w_list, index, w_item):
         self.switch_to_integer_strategy(w_list)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to