Author: Carl Friedrich Bolz <[email protected]>
Branch: 
Changeset: r62660:cfcc5f6b1c72
Date: 2013-03-22 17:31 +0100
http://bitbucket.org/pypy/pypy/changeset/cfcc5f6b1c72/

Log:    a more efficient implementation of list multiplication for typed
        lists: so far multiplying would always clone the list and then use
        inplace_mul

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -1038,6 +1038,11 @@
         w_item = self.wrap(item)
         return w_item
 
+    def mul(self, w_list, times):
+        l = self.unerase(w_list.lstorage)
+        return W_ListObject.from_storage_and_strategy(
+            self.space, self.erase(l * times), self)
+
     def inplace_mul(self, w_list, times):
         l = self.unerase(w_list.lstorage)
         l *= times
diff --git a/pypy/objspace/std/test/test_listobject.py 
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -200,6 +200,15 @@
         w_res = self.space.mul(w(n), w_lis)
         assert self.space.eq_w(w_lis3, w_res)
 
+    def test_mul_does_not_clone(self):
+        # only testing right mul at the moment
+        w = self.space.wrap
+        arg = w(2)
+        w_lis = W_ListObject(self.space, [arg])
+        w_lis.clone = None
+        # does not crash
+        self.space.mul(w_lis, w(5))
+
     def test_setitem(self):
         w = self.space.wrap
         w_list = W_ListObject(self.space, [w(5), w(3)])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to