Author: Lukas Diekmann <[email protected]>
Branch: list-strategies
Changeset: r47419:05ab11979465
Date: 2011-02-16 11:55 +0100
http://bitbucket.org/pypy/pypy/changeset/05ab11979465/
Log: Implemented inplace_mul in strategies
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
@@ -85,6 +85,11 @@
def getitems(self):
return self.strategy.getitems(self)
+ # ___________________________________________________
+
+ def inplace_mul(self, times):
+ self.strategy.inplace_mul(self, times)
+
registerimplementation(W_ListObject)
@@ -107,6 +112,9 @@
def append(self, w_list, w_item):
raise NotImplementedError
+ def inplace_mul(self, w_list, times):
+ raise NotImplementedError
+
class EmptyListStrategy(ListStrategy):
def init_from_list_w(self, w_list, list_w):
assert len(list_w) == 0
@@ -137,6 +145,9 @@
w_list.wrappeditems.append(w_item)
w_list.strategy.init_from_list_w(w_list, w_list.wrappeditems)
+ def inplace_mul(self, w_list, times):
+ return
+
class ObjectListStrategy(ListStrategy):
def init_from_list_w(self, w_list, list_w):
w_list.storage = cast_to_void_star(list_w, "object")
@@ -163,6 +174,10 @@
def append(self, w_list, w_item):
cast_from_void_star(w_list.storage, "object").append(w_item)
+ def inplace_mul(self, w_list, times):
+ list_w = cast_from_void_star(w_list.storage, "object")
+ list_w *= times
+
class IntegerListStrategy(ListStrategy):
def init_from_list_w(self, w_list, list_w):
@@ -198,6 +213,10 @@
w_list.strategy.init_from_list_w(w_list, items_w)
w_list.append(w_item)
+ def inplace_mul(self, w_list, times):
+ list_w = cast_from_void_star(w_list.storage, "integer")
+ list_w *= times
+
class StringListStrategy(ListStrategy):
def init_from_list_w(self, w_list, list_w):
@@ -233,6 +252,12 @@
w_list.strategy.init_from_list_w(w_list, list_w)
w_list.append(w_item)
+ def inplace_mul(self, w_list, times):
+ list_w = cast_from_void_star(w_list.storage, "string")
+ list_w *= times
+
+# _______________________________________________________
+
init_signature = Signature(['sequence'], None, None)
init_defaults = [None]
@@ -342,7 +367,7 @@
if e.match(space, space.w_TypeError):
raise FailedToImplement
raise
- w_list.wrappeditems *= times
+ w_list.inplace_mul(times)
return w_list
def eq__List_List(space, w_list1, w_list2):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit