[pypy-commit] pypy list-strategies: Avoid duplicate copy in RangeList.mul() + tests
l.diekmann
noreply at buildbot.pypy.org
Fri Sep 23 13:13:05 CEST 2011
Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47496:be8327c01c6a
Date: 2011-04-12 12:02 +0200
http://bitbucket.org/pypy/pypy/changeset/be8327c01c6a/
Log: Avoid duplicate copy in RangeList.mul() + tests
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
@@ -387,9 +387,11 @@
w_list.append(w_item)
def mul(self, w_list, times):
- #XXX maybe faster to get unwrapped items and create new integer list?
- w_newlist = w_list.clone()
- w_newlist.inplace_mul(times)
+ l = self._getitems_range(w_list, False)
+ l *= times
+ strategy = self.space.fromcache(IntegerListStrategy)
+ storage = strategy.cast_to_void_star(l)
+ w_newlist = W_ListObject.from_storage_and_strategy(self.space, storage, strategy)
return w_newlist
def inplace_mul(self, w_list, times):
@@ -672,6 +674,7 @@
return w_item
def mul(self, w_list, times):
+ # clone
w_newlist = w_list.clone()
w_newlist.inplace_mul(times)
return w_newlist
diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -312,6 +312,12 @@
l3 = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap(2), self.space.wrap(3), self.space.wrap(1), self.space.wrap(2), self.space.wrap(3)])
assert self.space.eq_w(l2, l3)
+ l4 = make_range_list(self.space, 1, 1, 3)
+ assert self.space.eq_w(l4, l1)
+
+ l5 = l4.mul(2)
+ assert self.space.eq_w(l5, l3)
+
def test_mul_same_strategy_but_different_object(self):
l1 = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap(2), self.space.wrap(3)])
l2 = l1.mul(1)
More information about the pypy-commit
mailing list