[pypy-svn] r70444 - in pypy/branch/morearraycopy/pypy: rlib rpython rpython/lltypesystem

arigo at codespeak.net arigo at codespeak.net
Thu Jan 7 21:34:26 CET 2010


Author: arigo
Date: Thu Jan  7 21:34:25 2010
New Revision: 70444

Modified:
   pypy/branch/morearraycopy/pypy/rlib/rgc.py
   pypy/branch/morearraycopy/pypy/rpython/lltypesystem/rlist.py
   pypy/branch/morearraycopy/pypy/rpython/rlist.py
Log:
Use another approach, more oo-friendly.


Modified: pypy/branch/morearraycopy/pypy/rlib/rgc.py
==============================================================================
--- pypy/branch/morearraycopy/pypy/rlib/rgc.py	(original)
+++ pypy/branch/morearraycopy/pypy/rlib/rgc.py	Thu Jan  7 21:34:25 2010
@@ -1,5 +1,7 @@
 import gc
 from pypy.rpython.extregistry import ExtRegistryEntry
+from pypy.rlib.objectmodel import we_are_translated
+
 # ____________________________________________________________
 # General GC features
 
@@ -334,7 +336,12 @@
     from pypy.rpython.lltypesystem import lltype, llmemory
     from pypy.rlib.objectmodel import keepalive_until_here
 
-    assert source != dest
+    # supports non-overlapping copies only
+    if not we_are_translated():
+        if source == dest:
+            assert (source_start + length <= dest_start or
+                    dest_start + length <= source_start)
+
     TP = lltype.typeOf(source).TO
     assert TP == lltype.typeOf(dest).TO
     if isinstance(TP.OF, lltype.Ptr) and TP.OF.TO._gckind == 'gc':

Modified: pypy/branch/morearraycopy/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/branch/morearraycopy/pypy/rpython/lltypesystem/rlist.py	(original)
+++ pypy/branch/morearraycopy/pypy/rpython/lltypesystem/rlist.py	Thu Jan  7 21:34:25 2010
@@ -72,7 +72,6 @@
                                  "ll_newemptylist": ll_fixed_newemptylist,
                                  "ll_length": ll_fixed_length,
                                  "ll_items": ll_fixed_items,
-                                 "ll_copyitems": ll_fixed_copyitems,
                                  "ITEM": ITEM,
                                  "ll_getitem_fast": ll_fixed_getitem_fast,
                                  "ll_setitem_fast": ll_fixed_setitem_fast,
@@ -106,7 +105,6 @@
                                           "ll_newemptylist": ll_newemptylist,
                                           "ll_length": ll_length,
                                           "ll_items": ll_items,
-                                          "ll_copyitems": ll_copyitems,
                                           "ITEM": ITEM,
                                           "ll_getitem_fast": ll_getitem_fast,
                                           "ll_setitem_fast": ll_setitem_fast,
@@ -304,9 +302,6 @@
 def ll_items(l):
     return l.items
 
-def ll_copyitems(dst, dstindex, src, srcindex, length):
-    rgc.ll_arraycopy(src.ll_items(), dst.items, srcindex, dstindex, length)
-
 def ll_getitem_fast(l, index):
     ll_assert(index < l.length, "getitem out of bounds")
     return l.ll_items()[index]
@@ -337,9 +332,6 @@
 def ll_fixed_items(l):
     return l
 
-def ll_fixed_copyitems(dst, dstindex, src, srcindex, length):
-    rgc.ll_arraycopy(src.ll_items(), dst, srcindex, dstindex, length)
-
 def ll_fixed_getitem_fast(l, index):
     ll_assert(index < len(l), "fixed getitem out of bounds")
     return l[index]

Modified: pypy/branch/morearraycopy/pypy/rpython/rlist.py
==============================================================================
--- pypy/branch/morearraycopy/pypy/rpython/rlist.py	(original)
+++ pypy/branch/morearraycopy/pypy/rpython/rlist.py	Thu Jan  7 21:34:25 2010
@@ -11,15 +11,13 @@
 from pypy.rlib.debug import ll_assert
 from pypy.rlib.rarithmetic import ovfcheck, widen
 from pypy.rpython.annlowlevel import ADTInterface
+from pypy.rlib import rgc
 
 ADTIFixedList = ADTInterface(None, {
     'll_newlist':      (['SELF', Signed        ], 'self'),
     'll_length':       (['self'                ], Signed),
     'll_getitem_fast': (['self', Signed        ], 'item'),
     'll_setitem_fast': (['self', Signed, 'item'], Void),
-    'll_copyitems':    (['self', Signed, None, Signed, Signed], Void),
-                       # uses a catch-everything None because it can be
-                       # either a fixed or a non-fixed list
 })
 ADTIList = ADTInterface(ADTIFixedList, {
     '_ll_resize_ge':   (['self', Signed        ], Void),
@@ -528,10 +526,24 @@
     return LIST.ITEM
 
 
+def ll_arraycopy(source, dest, source_start, dest_start, length):
+    SRCTYPE = typeOf(source)
+    if isinstance(SRCTYPE, Ptr):
+        # lltype
+        rgc.ll_arraycopy(source.ll_items(), dest.ll_items(),
+                         source_start, dest_start, length)
+    else:
+        # ootype -- XXX improve the case of array->array copy?
+        i = 0
+        while i < length:
+            item = source.ll_getitem_fast(source_start + i)
+            dest.ll_setitem_fast(dest_start + i, item)
+            i += 1
+
 def ll_copy(RESLIST, l):
     length = l.ll_length()
     new_lst = RESLIST.ll_newlist(length)
-    new_lst.ll_copyitems(0, l, 0, length)
+    ll_arraycopy(l, new_lst, 0, 0, length)
     return new_lst
 
 def ll_len(l):
@@ -574,8 +586,8 @@
     except OverflowError:
         raise MemoryError
     l = RESLIST.ll_newlist(newlength)
-    l.ll_copyitems(0, l1, 0, len1)
-    l.ll_copyitems(len1, l2, 0, len2)
+    ll_arraycopy(l1, l, 0, 0, len1)
+    ll_arraycopy(l2, l, 0, len1, len2)
     return l
 
 def ll_insert_nonneg(l, index, newitem):
@@ -762,7 +774,7 @@
     except OverflowError:
         raise MemoryError
     l1._ll_resize_ge(newlength)
-    l1.ll_copyitems(len1, l2, 0, len2)
+    ll_arraycopy(l2, l1, 0, len1, len2)
 ll_extend.oopspec = 'list.extend(l1, l2)'
 
 def ll_extend_with_str(lst, s, getstrlen, getstritem):
@@ -855,7 +867,7 @@
     ll_assert(start <= len1, "list slice start larger than list length")
     newlength = len1 - start
     l = RESLIST.ll_newlist(newlength)
-    l.ll_copyitems(0, l1, start, newlength)
+    ll_arraycopy(l1, l, start, 0, newlength)
     return l
 ll_listslice_startonly._annenforceargs_ = (None, None, int)
 
@@ -868,14 +880,14 @@
         stop = length
     newlength = stop - start
     l = RESLIST.ll_newlist(newlength)
-    l.ll_copyitems(0, l1, start, newlength)
+    ll_arraycopy(l1, l, start, 0, newlength)
     return l
 
 def ll_listslice_minusone(RESLIST, l1):
     newlength = l1.ll_length() - 1
     ll_assert(newlength >= 0, "empty list is sliced with [:-1]")
     l = RESLIST.ll_newlist(newlength)
-    l.ll_copyitems(0, l1, 0, newlength)
+    ll_arraycopy(l1, l, 0, 0, newlength)
     return l
 
 def ll_listdelslice_startonly(l, start):
@@ -921,7 +933,7 @@
     ll_assert(count == stop - start,
                  "setslice cannot resize lists in RPython")
     # XXX ...but it would be easy enough to support if really needed
-    l1.ll_copyitems(start, l2, 0, count)
+    ll_arraycopy(l2, l1, 0, start, count)
 ll_listsetslice.oopspec = 'list.setslice(l1, start, stop, l2)'
 
 # ____________________________________________________________



More information about the Pypy-commit mailing list