Hi.
I've made the different [slow] list implementations even slower !
While integrating the blist implementation, I found out that the chosen
implementation isn't even used when instantiating with "list()", and
neither in some other usecases. By correcting that, a bug in the chunked
implementation got uncovered, which I also fixed. I also added
"make_implementation_with_one_item()" to have the instantiation of the
implementations in one place so that it's easier to add new ones.
If they seem good, could someone commit these changes (is that diff
format good?). Would you trust me with commit rights, or should I still
send patches?
The test demonstrates the bugs, but I thougth of later adding a
BaseAppTest_ListMultiObject class with magic to test if the
implementations that the subclasses test are really used. Does that
sound good?
Index: objspace/std/listmultiobject.py
===================================================================
--- objspace/std/listmultiobject.py (revision 44498)
+++ objspace/std/listmultiobject.py (working copy)
@@ -12,7 +12,7 @@
# An empty list always is an EmptyListImplementation.
#
-# RDictImplementation -- standard implementation
+# RListImplementation -- standard implementation
# StrListImplementation -- lists consisting only of strings
# ChunkedListImplementation -- when having set the withchunklist option
# SmartResizableListImplementation -- when having set the
@@ -87,7 +87,7 @@
for i in range(slicelength):
res_w[i] = self.getitem(start)
start += step
- return RListImplementation(self.space, res_w)
+ return make_implementation(self.space, res_w)
def delitem_slice_step(self, start, stop, step, slicelength):
n = self.length()
@@ -368,8 +368,8 @@
length = self._length
self._grow()
- for j in range(length - 1, 0, -1):
- self.setitem(j + 1, self.getitem(j))
+ for j in range(length, i, -1):
+ self.setitem(j, self.getitem(j-1))
self.setitem(i, w_item)
return self
@@ -399,13 +399,7 @@
class EmptyListImplementation(ListImplementation):
def make_list_with_one_item(self, w_item):
space = self.space
- if space.config.objspace.std.withfastslice:
- return SliceTrackingListImplementation(space, [w_item])
- w_type = space.type(w_item)
- if space.is_w(w_type, space.w_str):
- strlist = [space.str_w(w_item)]
- return StrListImplementation(space, strlist)
- return RListImplementation(space, [w_item])
+ return make_implementation_with_one_item(space, w_item)
def length(self):
return 0
@@ -834,6 +828,27 @@
else:
return RListImplementation(space, list_w)
+def make_implementation_with_one_item(space, w_item):
+ if space.config.objspace.std.withfastslice:
+ return SliceTrackingListImplementation(space, [w_item])
+ if space.config.objspace.std.withsmartresizablelist:
+ from pypy.objspace.std.smartresizablelist import \
+ SmartResizableListImplementation
+ impl = SmartResizableListImplementation(space)
+ impl.append(w_item)
+ return impl
+ if space.config.objspace.std.withchunklist:
+ return ChunkedListImplementation(space, [w_item])
+ if space.config.objspace.std.withblist:
+ from pypy.objspace.std.blistimplementation import \
+ BListImplementation
+ return BListImplementation(space, [w_item])
+ w_type = space.type(w_item)
+ if space.is_w(w_type, space.w_str):
+ strlist = [space.str_w(w_item)]
+ return StrListImplementation(space, strlist)
+ return RListImplementation(space, [w_item])
+
def convert_list_w(space, list_w):
if not list_w:
impl = space.fromcache(State).empty_impl
@@ -884,7 +899,7 @@
if w_iterable is not EMPTY_LIST:
list_w = space.unpackiterable(w_iterable)
if list_w:
- w_list.implementation = RListImplementation(space, list_w)
+ w_list.implementation = make_implementation(space, list_w)
return
w_list.implementation = space.fromcache(State).empty_impl
@@ -1304,9 +1319,8 @@
sorterclass = CustomKeySort
else:
sorterclass = SimpleSort
- impl = w_list.implementation.to_rlist()
- w_list.implementation = impl
- items = impl.list_w
+ impl=w_list.implementation
+ items = impl.get_list_w()
sorter = sorterclass(items, impl.length())
sorter.space = space
sorter.w_cmp = w_cmp
@@ -1349,8 +1363,7 @@
mucked = w_list.implementation.length() > 0
# put the items back into the list
- impl.list_w = sorter.list
- w_list.implementation = impl
+ w_list.implementation = make_implementation(space, sorter.list)
if mucked:
raise OperationError(space.w_ValueError,
Index: objspace/std/test/test_listmultiobject.py
===================================================================
--- objspace/std/test/test_listmultiobject.py (revision 44498)
+++ objspace/std/test/test_listmultiobject.py (working copy)
@@ -144,3 +144,15 @@
def teardown_class(cls):
_set_chunk_size_bits(cls.chunk_size_bits)
+ def test_chunklist_is_implementation_used(self):
+ import __pypy__
+ l = ["1", "2", "3", "4", "5"]
+ assert "ChunkedListImplementation" in __pypy__.internal_repr(l)
+ l = list(["1", "2", "3", "4", "5"])
+ assert "ChunkedListImplementation" in __pypy__.internal_repr(l)
+ l=[]
+ l.append('a')
+ assert "ChunkedListImplementation" in __pypy__.internal_repr(l)
+ l = ["6", "8", "3", "1", "5"]
+ l.sort()
+ assert "ChunkedListImplementation" in __pypy__.internal_repr(l)
_______________________________________________
[email protected]
http://codespeak.net/mailman/listinfo/pypy-dev