Author: Vincent Legoll <vincent.leg...@idgrilles.fr>
Branch: fix-2198
Changeset: r81363:72204e7474a5
Date: 2015-12-16 13:28 +0100
http://bitbucket.org/pypy/pypy/changeset/72204e7474a5/

Log:    Fix translation

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
@@ -1473,14 +1473,17 @@
             return # shortcut, really there's nothing to do
         items = self.unerase(w_list.lstorage)
         if step == 1:  # Support list resizing for non-extended slices
-            delta = slicelength - len2
-            if delta > 0:
-                # start < 0 is only possible with slicelength == 0
-                assert start >= 0
-                if len2 == 0:
-                    del items[start:start + delta]
-                    return # shortcut, we already did all that was needed
-            items[start:start + slicelength] = self.unerase(w_other.lstorage)
+            len1 = w_list.length()
+            # Ensure non-negative slicing
+            if start <= -len1:
+                start = 0
+            elif start < 0:
+                start += len1
+            assert start >= 0
+            if len2 == 0 and slicelength > 0: # shortcut, we already did all 
that was needed
+                del items[start:start + slicelength]
+            else:
+                items[start:start + slicelength] = 
self.unerase(w_other.lstorage)
             return
         elif len2 != slicelength:  # No resize for extended slices
             raise oefmt(self.space.w_ValueError,
@@ -1494,9 +1497,18 @@
             # self.unerase is valid for both of them
             other_items = self.unerase(w_other.lstorage)
         if other_items is items:
-            if step > 0:
-                items[start:start + slicelength:step] = other_items
+            if step > 1:
+                # Always copy starting from the right to avoid
+                # having to make a shallow copy in the case where
+                # the source and destination lists are the same list.
+                i = len2 - 1
+                start += i * step
+                while i >= 0:
+                    items[start] = other_items[i]
+                    start -= step
+                    i -= 1
             else: # step can only be -1 here, so it's equivalent to :
+                assert step == -1
                 w_list.reverse()
             return
         for i in range(len2):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to