Author: Lukas Diekmann <[email protected]>
Branch: list-strategies
Changeset: r47413:3f7f05555c7b
Date: 2011-01-26 11:45 +0100
http://bitbucket.org/pypy/pypy/changeset/3f7f05555c7b/
Log: Replaced more w_list.wrappeditems by using the (temporary) method
w_list.getitems()
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
@@ -54,6 +54,9 @@
def getslice(self, start, stop, step, length):
return self.strategy.getslice(self, start, stop, step, length)
+ def getitems(self):
+ return self.strategy.getitems(self)
+
registerimplementation(W_ListObject)
@@ -70,6 +73,9 @@
def getslice(self, w_list, start, stop, step, length):
raise NotImplementedError
+ def getitems(self, w_list):
+ raise NotImplementedError
+
class EmptyListStrategy(ListStrategy):
def init_from_list_w(self, w_list, list_w):
assert len(list_w) == 0
@@ -84,6 +90,9 @@
def getslice(self, w_list, start, stop, step, length):
return W_ListObject([])
+ def getitems(self, w_list):
+ return []
+
class ObjectListStrategy(ListStrategy):
def init_from_list_w(self, w_list, list_w):
w_list.storage = cast_to_void_star(list_w, "object")
@@ -104,6 +113,9 @@
start += step
return W_ListObject(subitems_w)
+ def getitems(self, w_list):
+ return cast_from_void_star(w_list.storage, "object")
+
init_signature = Signature(['sequence'], None, None)
init_defaults = [None]
@@ -119,7 +131,7 @@
# This is commented out to avoid assigning a new RPython list to
# 'wrappeditems', which defeats the W_FastSeqIterObject optimization.
#
- items_w = w_list.wrappeditems
+ items_w = w_list.getitems()
del items_w[:]
if w_iterable is not None:
w_iterator = space.iter(w_iterable)
@@ -163,7 +175,7 @@
def delslice__List_ANY_ANY(space, w_list, w_start, w_stop):
length = w_list.length()
start, stop = normalize_simple_slice(space, length, w_start, w_stop)
- _delitem_slice_helper(space, w_list.wrappeditems, start, 1, stop-start)
+ _delitem_slice_helper(space, w_list.getitems(), start, 1, stop-start)
def contains__List_ANY(space, w_list, w_obj):
# needs to be safe against eq_w() mutating the w_list behind our back
@@ -176,10 +188,10 @@
def iter__List(space, w_list):
from pypy.objspace.std import iterobject
- return iterobject.W_FastListIterObject(w_list, w_list.wrappeditems)
+ return iterobject.W_FastListIterObject(w_list, w_list.getitems())
def add__List_List(space, w_list1, w_list2):
- return W_ListObject(w_list1.wrappeditems + w_list2.wrappeditems)
+ return W_ListObject(w_list1.getitems() + w_list2.getitems())
def inplace_add__List_ANY(space, w_list1, w_iterable2):
@@ -197,7 +209,7 @@
if e.match(space, space.w_TypeError):
raise FailedToImplement
raise
- return W_ListObject(w_list.wrappeditems * times)
+ return W_ListObject(w_list.getitems() * times)
def mul__List_ANY(space, w_list, w_times):
return mul_list_times(space, w_list, w_times)
@@ -217,8 +229,8 @@
def eq__List_List(space, w_list1, w_list2):
# needs to be safe against eq_w() mutating the w_lists behind our back
- items1_w = w_list1.wrappeditems
- items2_w = w_list2.wrappeditems
+ items1_w = w_list1.getitems()
+ items2_w = w_list2.getitems()
return equal_wrappeditems(space, items1_w, items2_w)
def equal_wrappeditems(space, items1_w, items2_w):
@@ -258,12 +270,12 @@
return space.newbool(len(items1_w) > len(items2_w))
def lt__List_List(space, w_list1, w_list2):
- return lessthan_unwrappeditems(space, w_list1.wrappeditems,
- w_list2.wrappeditems)
+ return lessthan_unwrappeditems(space, w_list1.getitems(),
+ w_list2.getitems())
def gt__List_List(space, w_list1, w_list2):
- return greaterthan_unwrappeditems(space, w_list1.wrappeditems,
- w_list2.wrappeditems)
+ return greaterthan_unwrappeditems(space, w_list1.getitems(),
+ w_list2.getitems())
def delitem__List_ANY(space, w_list, w_idx):
idx = get_list_index(space, w_idx)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit