[pypy-commit] pypy list-strategies: refactored mul (general implementation in ListStrategy)
l.diekmann
noreply at buildbot.pypy.org
Fri Sep 23 13:15:35 CEST 2011
Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47552:0816546cd53e
Date: 2011-09-14 13:33 +0200
http://bitbucket.org/pypy/pypy/changeset/0816546cd53e/
Log: refactored mul (general implementation in ListStrategy)
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
@@ -209,7 +209,9 @@
raise NotImplementedError
def mul(self, w_list, times):
- raise NotImplementedError
+ w_newlist = w_list.clone()
+ w_newlist.inplace_mul(times)
+ return w_newlist
def inplace_mul(self, w_list, times):
raise NotImplementedError
@@ -270,13 +272,13 @@
raise IndexError
def getslice(self, w_list, start, stop, step, length):
- return W_ListObject(self.space, self.emptylist)
+ return W_ListObject(self.space, self.cached_emptylist_w)
def getitems(self, w_list):
- return self.emptylist
+ return self.cached_emptylist_w
def getitems_copy(self, w_list):
- return self.emptylist
+ return self.cached_emptylist_w
def getstorage_copy(self, w_list):
return self.erase(None)
@@ -297,9 +299,6 @@
self.switch_to_correct_strategy(w_list, w_item)
w_list.append(w_item)
- def mul(self, w_list, times):
- return w_list.clone()
-
def inplace_mul(self, w_list, times):
return
@@ -447,19 +446,6 @@
w_list.switch_to_object_strategy()
w_list.append(w_item)
- def mul(self, w_list, times):
- #XXX is this faster?
- if times == 0:
- strategy = self.space.fromcache(IntegerListStrategy)
- storage = strategy.erase([])
- else:
- l = self._getitems_range(w_list, False)
- l *= times
- strategy = self.space.fromcache(IntegerListStrategy)
- storage = strategy.erase(l)
- w_newlist = W_ListObject.from_storage_and_strategy(self.space, storage, strategy)
- return w_newlist
-
def inplace_mul(self, w_list, times):
self.switch_to_integer_strategy(w_list)
w_list.inplace_mul(times)
@@ -757,12 +743,6 @@
w_item = self.wrap(item)
return w_item
- def mul(self, w_list, times):
- # XXX can't this be the default implementation in ListStrategy?
- w_newlist = w_list.clone()
- w_newlist.inplace_mul(times)
- return w_newlist
-
def inplace_mul(self, w_list, times):
l = self.unerase(w_list.lstorage)
l *= times
More information about the pypy-commit
mailing list