[pypy-svn] r52739 - pypy/dist/pypy/rpython/lltypesystem

fijal at codespeak.net fijal at codespeak.net
Wed Mar 19 20:24:38 CET 2008


Author: fijal
Date: Wed Mar 19 20:24:37 2008
New Revision: 52739

Modified:
   pypy/dist/pypy/rpython/lltypesystem/lltype.py
   pypy/dist/pypy/rpython/lltypesystem/rlist.py
Log:
Make rpython list slightly faster, by using memcopy


Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py	Wed Mar 19 20:24:37 2008
@@ -1311,6 +1311,7 @@
         self._parent_type = typeOf(parent)
         self._parent_index = parentindex
         if (isinstance(self._parent_type, Struct)
+            and self._parent_type._names
             and parentindex in (self._parent_type._names[0], 0)
             and self._TYPE._gckind == typeOf(parent)._gckind):
             # keep strong reference to parent, we share the same allocation

Modified: pypy/dist/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rlist.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rlist.py	Wed Mar 19 20:24:37 2008
@@ -19,7 +19,7 @@
 from pypy.rlib.debug import ll_assert
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rpython.lltypesystem.llmemory import cast_ptr_to_adr, raw_memclear,\
-     raw_memcopy, sizeof, itemoffsetof
+     raw_memcopy, sizeof, itemoffsetof, offsetof
 from pypy.rpython.lltypesystem import rffi
 
 # ____________________________________________________________
@@ -309,12 +309,13 @@
         p = before_len - 1
     else:
         p = new_allocated - 1
-    while p >= 0:
-        newitems[p] = items[p]
-        ITEM = typeOf(l).TO.ITEM
-        if isinstance(ITEM, Ptr):
-            items[p] = nullptr(ITEM.TO)
-        p -= 1
+    ITEM = typeOf(l).TO.ITEM
+    source = cast_ptr_to_adr(items) + itemoffsetof(typeOf(l.items).TO, 0)
+    dest = cast_ptr_to_adr(newitems) + itemoffsetof(typeOf(l.items).TO, 0)
+    s = p + 1
+    raw_memcopy(source, dest, sizeof(ITEM) * s)
+    if isinstance(ITEM, Ptr):
+        raw_memclear(source, sizeof(ITEM) * s)
     l.length = newsize
     l.items = newitems
 _ll_list_resize_really._annenforceargs_ = (None, int)



More information about the Pypy-commit mailing list