[pypy-commit] pypy remove-list-smm-2: Remove list.__getitem__/__getslice__ multi-methods.
Manuel Jacob
noreply at buildbot.pypy.org
Wed May 15 19:44:40 CEST 2013
Author: Manuel Jacob
Branch: remove-list-smm-2
Changeset: r64183:c391c5a8e7f6
Date: 2013-05-15 15:54 +0200
http://bitbucket.org/pypy/pypy/changeset/c391c5a8e7f6/
Log: Remove list.__getitem__/__getslice__ multi-methods.
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
@@ -342,6 +342,31 @@
result = self.length()
return wrapint(space, result)
+ def descr_getitem(self, space, w_index):
+ if isinstance(w_index, W_SliceObject):
+ # XXX consider to extend rlist's functionality?
+ length = self.length()
+ start, stop, step, slicelength = w_index.indices4(space, length)
+ assert slicelength >= 0
+ if slicelength == 0:
+ return make_empty_list(space)
+ return self.getslice(start, stop, step, slicelength)
+
+ try:
+ return self.getitem(get_list_index(space, w_index))
+ except IndexError:
+ raise OperationError(space.w_IndexError,
+ space.wrap("list index out of range"))
+
+ def descr_getslice(self, space, w_start, w_stop):
+ length = self.length()
+ start, stop = normalize_simple_slice(space, length, w_start, w_stop)
+
+ slicelength = stop - start
+ if slicelength == 0:
+ return make_empty_list(space)
+ return self.getslice(start, stop, 1, stop - start)
+
def descr_reversed(self, space):
'L.__reversed__() -- return a reverse iterator over the list'
from pypy.objspace.std.iterobject import W_ReverseSeqIterObject
@@ -1384,31 +1409,6 @@
init_signature = Signature(['sequence'], None, None)
init_defaults = [None]
-def getitem__List_ANY(space, w_list, w_index):
- try:
- return w_list.getitem(get_list_index(space, w_index))
- except IndexError:
- raise OperationError(space.w_IndexError,
- space.wrap("list index out of range"))
-
-def getitem__List_Slice(space, w_list, w_slice):
- # XXX consider to extend rlist's functionality?
- length = w_list.length()
- start, stop, step, slicelength = w_slice.indices4(space, length)
- assert slicelength >= 0
- if slicelength == 0:
- return make_empty_list(space)
- return w_list.getslice(start, stop, step, slicelength)
-
-def getslice__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)
-
- slicelength = stop - start
- if slicelength == 0:
- return make_empty_list(space)
- return w_list.getslice(start, stop, 1, stop - start)
-
def setslice__List_ANY_ANY_List(space, w_list, w_start, w_stop, w_other):
length = w_list.length()
start, stop = normalize_simple_slice(space, length, w_start, w_stop)
@@ -1693,6 +1693,9 @@
__len__ = interp2app(W_ListObject.descr_len),
+ __getitem__ = interp2app(W_ListObject.descr_getitem),
+ __getslice__ = interp2app(W_ListObject.descr_getslice),
+
sort = interp2app(W_ListObject.descr_sort),
index = interp2app(W_ListObject.descr_index),
append = interp2app(W_ListObject.append),
More information about the pypy-commit
mailing list