[pypy-svn] r60931 - pypy/trunk/pypy/rpython/lltypesystem

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jan 13 18:03:55 CET 2009


Author: cfbolz
Date: Tue Jan 13 18:03:53 2009
New Revision: 60931

Modified:
   pypy/trunk/pypy/rpython/lltypesystem/rlist.py
Log:
Incredible optimization: don't allocate Arrays of length 0 for lists that are
being shrunk to size 0.


Modified: pypy/trunk/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rlist.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rlist.py	Tue Jan 13 18:03:53 2009
@@ -200,8 +200,9 @@
     # The growth pattern is:  0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
     if newsize <= 0:
         ll_assert(newsize == 0, "negative list length")
-        new_allocated = 0
-        # XXX why not use _ll_prebuilt_empty_array here?
+        l.length = 0
+        l.items = _ll_new_empty_item_array(typeOf(l).TO)
+        return
     else:
         if newsize < 9:
             some = 3
@@ -295,13 +296,16 @@
     return malloc(LISTITEM, 0)
 _ll_prebuilt_empty_array._annspecialcase_ = 'specialize:memo'
 
+def _ll_new_empty_item_array(LIST):
+    if INITIAL_EMPTY_LIST_ALLOCATION > 0:
+        return malloc(LIST.items.TO, INITIAL_EMPTY_LIST_ALLOCATION)
+    else:
+        return _ll_prebuilt_empty_array(LIST.items.TO)
+
 def ll_newemptylist(LIST):
     l = malloc(LIST)
     l.length = 0
-    if INITIAL_EMPTY_LIST_ALLOCATION > 0:
-        l.items = malloc(LIST.items.TO, INITIAL_EMPTY_LIST_ALLOCATION)
-    else:
-        l.items = _ll_prebuilt_empty_array(LIST.items.TO)
+    l.items = _ll_new_empty_item_array(LIST)
     return l
 ll_newemptylist = typeMethod(ll_newemptylist)
 ll_newemptylist.oopspec = 'newlist(0)'



More information about the Pypy-commit mailing list