[pypy-commit] pypy list-strategies: replaced deleteitem with pop

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


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47546:c3fc636917a5
Date: 2011-09-13 14:57 +0200
http://bitbucket.org/pypy/pypy/changeset/c3fc636917a5/

Log:	replaced deleteitem with pop

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
@@ -133,10 +133,6 @@
     def inplace_mul(self, times):
         self.strategy.inplace_mul(self, times)
 
-    def deleteitem(self, index):
-        # XXX remove the deleteitem method, always use pop
-        self.strategy.deleteitem(self, index)
-
     def deleteslice(self, start, step, length):
         self.strategy.deleteslice(self, start, step, length)
 
@@ -206,9 +202,6 @@
     def inplace_mul(self, w_list, times):
         raise NotImplementedError
 
-    def deleteitem(self, w_list, index):
-        raise NotImplementedError
-
     def deleteslice(self, w_list, start, step, slicelength):
         raise NotImplementedError
 
@@ -287,9 +280,6 @@
     def inplace_mul(self, w_list, times):
         return
 
-    def deleteitem(self, w_list, index):
-        raise IndexError
-
     def deleteslice(self, w_list, start, step, slicelength):
         pass
 
@@ -437,10 +427,6 @@
         self.switch_to_integer_strategy(w_list)
         w_list.inplace_mul(times)
 
-    def deleteitem(self, w_list, index):
-        self.switch_to_integer_strategy(w_list)
-        w_list.deleteitem(index)
-
     def deleteslice(self, w_list, start, step, slicelength):
         self.switch_to_integer_strategy(w_list)
         w_list.deleteslice(start, step, slicelength)
@@ -676,13 +662,6 @@
             items[start] = other_items[i]
             start += step
 
-    def deleteitem(self, w_list, index):
-        l = self.unerase(w_list.lstorage)
-        try:
-            del l[index]
-        except IndexError:
-            raise
-
     def deleteslice(self, w_list, start, step, slicelength):
         items = self.unerase(w_list.lstorage)
         if slicelength==0:
@@ -1050,8 +1029,10 @@
 
 def delitem__List_ANY(space, w_list, w_idx):
     idx = get_list_index(space, w_idx)
+    if idx < 0:
+        idx += w_list.length()
     try:
-        w_list.deleteitem(idx)
+        w_list.pop(idx)
     except IndexError:
         raise OperationError(space.w_IndexError,
                              space.wrap("list deletion index out of range"))
@@ -1161,7 +1142,7 @@
     while i < w_list.length():
         if space.eq_w(w_list.getitem(i), w_any):
             if i < w_list.length(): # if this is wrong the list was changed
-                w_list.deleteitem(i)
+                w_list.pop(i)
             return space.w_None
         i += 1
     raise OperationError(space.w_ValueError,


More information about the pypy-commit mailing list