[pypy-svn] r70422 - in pypy/branch/morearraycopy/pypy/rpython: . lltypesystem test
arigo at codespeak.net
arigo at codespeak.net
Wed Jan 6 23:26:18 CET 2010
Author: arigo
Date: Wed Jan 6 23:26:18 2010
New Revision: 70422
Modified:
pypy/branch/morearraycopy/pypy/rpython/lltypesystem/rlist.py
pypy/branch/morearraycopy/pypy/rpython/rlist.py
pypy/branch/morearraycopy/pypy/rpython/test/test_rlist.py
Log:
Add an ADT method ll_copyitems(), and start using it for ll_copy().
Only on lltype for now.
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 Wed Jan 6 23:26:18 2010
@@ -72,6 +72,7 @@
"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,
@@ -105,6 +106,7 @@
"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,
@@ -302,6 +304,9 @@
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]
@@ -332,6 +337,9 @@
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 Wed Jan 6 23:26:18 2010
@@ -17,6 +17,9 @@
'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 +531,7 @@
def ll_copy(RESLIST, l):
length = l.ll_length()
new_lst = RESLIST.ll_newlist(length)
- i = 0
- while i < length:
- new_lst.ll_setitem_fast(i, l.ll_getitem_fast(i))
- i += 1
+ new_lst.ll_copyitems(0, l, 0, length)
return new_lst
def ll_len(l):
Modified: pypy/branch/morearraycopy/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/branch/morearraycopy/pypy/rpython/test/test_rlist.py (original)
+++ pypy/branch/morearraycopy/pypy/rpython/test/test_rlist.py Wed Jan 6 23:26:18 2010
@@ -410,13 +410,18 @@
assert res.item2 == 9
def test_bltn_list(self):
- def dummyfn():
- l1 = [42]
- l2 = list(l1)
- l2[0] = 0
- return l1[0]
- res = self.interpret(dummyfn, ())
- assert res == 42
+ # test for ll_copy()
+ for resize1 in [False, True]:
+ for resize2 in [False, True]:
+ def dummyfn():
+ l1 = [42]
+ if resize1: l1.append(43)
+ l2 = list(l1)
+ if resize2: l2.append(44)
+ l2[0] = 0
+ return l1[0]
+ res = self.interpret(dummyfn, ())
+ assert res == 42
def test_is_true(self):
def is_true(lst):
More information about the Pypy-commit
mailing list