[pypy-svn] r37771 - in pypy/dist/pypy/objspace/std: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Feb 1 22:48:30 CET 2007
Author: cfbolz
Date: Thu Feb 1 22:48:28 2007
New Revision: 37771
Modified:
pypy/dist/pypy/objspace/std/listobject.py
pypy/dist/pypy/objspace/std/test/test_listobject.py
Log:
add a extend__List_List and inplace_add__List_List implementations to not have
to call space.unpackiterable on the other list (which loops over the list,
constructs a copy of it, etc, etc). Makes list.extend(list) a lot faster.
Modified: pypy/dist/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listobject.py (original)
+++ pypy/dist/pypy/objspace/std/listobject.py Thu Feb 1 22:48:28 2007
@@ -92,6 +92,10 @@
list_extend__List_ANY(space, w_list1, w_iterable2)
return w_list1
+def inplace_add__List_List(space, w_list1, w_list2):
+ list_extend__List_List(space, w_list1, w_list2)
+ return w_list1
+
def mul_list_times(space, w_list, w_times):
try:
times = space.int_w(w_times)
@@ -358,6 +362,10 @@
w_list.wrappeditems.append(w_any)
return space.w_None
+def list_extend__List_List(space, w_list, w_other):
+ w_list.wrappeditems += w_other.wrappeditems
+ return space.w_None
+
def list_extend__List_ANY(space, w_list, w_any):
w_list.wrappeditems += space.unpackiterable(w_any)
return space.w_None
Modified: pypy/dist/pypy/objspace/std/test/test_listobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_listobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_listobject.py Thu Feb 1 22:48:28 2007
@@ -370,6 +370,12 @@
assert l is l0
assert l == [1,2]
+ def test_extend_iterable(self):
+ l = l0 = [1]
+ l.extend(iter([1, 2, 3, 4]))
+ assert l is l0
+ assert l == [1, 1, 2, 3, 4]
+
def test_sort(self):
l = l0 = [1, 5, 3, 0]
l.sort()
@@ -448,6 +454,12 @@
assert l is l0
assert l == [1,2,3,4,5]
+ def test_iadd_iterable(self):
+ l = l0 = [1,2,3]
+ l += iter([4,5])
+ assert l is l0
+ assert l == [1,2,3,4,5]
+
def test_imul(self):
l = l0 = [4,3]
l *= 2
More information about the Pypy-commit
mailing list