[pypy-svn] r70052 - pypy/branch/listcopyop/pypy/rpython/lltypesystem

arigo at codespeak.net arigo at codespeak.net
Thu Dec 10 18:02:58 CET 2009


Author: arigo
Date: Thu Dec 10 18:02:58 2009
New Revision: 70052

Modified:
   pypy/branch/listcopyop/pypy/rpython/lltypesystem/rlist.py
Log:
Fix two issues:

 * In case of list shrinking, don't use new_allocated, but newsize.
   This avoids putting random items in the extra space.  (I think a
   test could show the problem if needed.)

 * Don't call ll_arraycopy() at all if there were no items previously,
   to avoid copying the GC flags of the prebuilt empty array.


Modified: pypy/branch/listcopyop/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/lltypesystem/rlist.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/lltypesystem/rlist.py	Thu Dec 10 18:02:58 2009
@@ -207,14 +207,17 @@
         except OverflowError:
             raise MemoryError
     # XXX consider to have a real realloc
+    # new_allocated is a bit more than newsize, enough to ensure an amortized
+    # linear complexity for e.g. repeated usage of l.append().
     items = l.items
     newitems = malloc(typeOf(l).TO.items.TO, new_allocated)
     before_len = l.length
-    if before_len < new_allocated:
-        p = before_len
-    else:
-        p = new_allocated
-    rgc.ll_arraycopy(items, newitems, 0, 0, p)
+    if before_len:   # avoids copying GC flags from the prebuilt_empty_array
+        if before_len < newsize:
+            p = before_len
+        else:
+            p = newsize
+        rgc.ll_arraycopy(items, newitems, 0, 0, p)
     l.length = newsize
     l.items = newitems
 _ll_list_resize_really._annenforceargs_ = (None, int)



More information about the Pypy-commit mailing list