[pypy-svn] r10275 - pypy/dist/pypy/objspace/std

tismer at codespeak.net tismer at codespeak.net
Sun Apr 3 22:27:38 CEST 2005


Author: tismer
Date: Sun Apr  3 22:27:38 2005
New Revision: 10275

Modified:
   pypy/dist/pypy/objspace/std/listobject.py
Log:
reverted the change. Keeping stuff in an extra list which gets
deleted after the operation is finished is way stronger.
By explicitly deleting recycle[:], we should be quite
safe, regardless which strategy simplify() might adopt (I hope) :-)

Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py	(original)
+++ pypy/dist/pypy/objspace/std/listobject.py	Sun Apr  3 22:27:38 2005
@@ -439,21 +439,16 @@
         ihigh = w_list.ob_size
     items = w_list.ob_item
     d = ihigh-ilow
+    # keep a reference to the objects to be removed,
     # preventing side effects during destruction
-    # first, re-arrange the list so unused elements are at the end.
-    newsize = w_list.ob_size - d
-    for i in range(ilow, newsize):
-        hold = items[i]
+    recycle = [items[i] for i in range(ilow, ihigh)]
+    for i in range(ilow, w_list.ob_size - d):
         items[i] = items[i+d]
-        items[i+d] = hold
-    # now get rid of the objects at the end, always
-    # keeping the list consistent
-    while w_list.ob_size > newsize:
-        p = w_list.ob_size-1
-        hold = w_list.ob_item[p]
-        w_list.ob_size = p
-        w_list.ob_item[p] = None
-        del hold
+        items[i+d] = None
+    w_list.ob_size -= d
+    # now we can destruct recycle safely, regardless of
+    # side-effects to the list
+    del recycle[:]
 
 # note that the default value will come back wrapped!!!
 def list_pop__List_ANY(space, w_list, w_idx=-1):



More information about the Pypy-commit mailing list