[pypy-svn] r39777 - in pypy/dist/pypy/objspace/std: . test
xoraxax at codespeak.net
xoraxax at codespeak.net
Sat Mar 3 12:28:57 CET 2007
Author: xoraxax
Date: Sat Mar 3 12:28:54 2007
New Revision: 39777
Modified:
pypy/dist/pypy/objspace/std/listmultiobject.py
pypy/dist/pypy/objspace/std/test/test_listmultiobject.py
Log:
Fixed a few remaining bugs in the ChunkList.
Modified: pypy/dist/pypy/objspace/std/listmultiobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listmultiobject.py (original)
+++ pypy/dist/pypy/objspace/std/listmultiobject.py Sat Mar 3 12:28:54 2007
@@ -283,14 +283,16 @@
free_slots = -self._length % CHUNK_SIZE
if free_slots < how_much:
to_allocate = how_much - free_slots
- for _ in range(0, (to_allocate / CHUNK_SIZE) + 1):
+ while to_allocate > 0:
self.chunks.append([None] * CHUNK_SIZE)
+ to_allocate -= CHUNK_SIZE
self._length += how_much
def length(self):
return self._length
def getitem(self, i):
+ assert i < self._length
return self.chunks[i >> CHUNK_SIZE_BITS][i & (CHUNK_SIZE - 1)]
def _get_chunks_slice(self, start, stop):
@@ -343,9 +345,10 @@
assert stop >= 0
delta = stop - start
+
for j in range(start + delta, length):
self.setitem(j - delta, self.getitem(j))
- first_unneeded_chunk = ((length - delta) >> CHUNK_SIZE) + 1
+ first_unneeded_chunk = ((length - delta) >> CHUNK_SIZE_BITS) + 1
assert first_unneeded_chunk >= 0
del self.chunks[first_unneeded_chunk:]
@@ -361,9 +364,10 @@
def insert(self, i, w_item):
assert i >= 0
+ length = self._length
self._grow()
- for j in range(i, self._length):
+ for j in range(length - 1, 0, -1):
self.setitem(j + 1, self.getitem(j))
self.setitem(i, w_item)
Modified: pypy/dist/pypy/objspace/std/test/test_listmultiobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_listmultiobject.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_listmultiobject.py Sat Mar 3 12:28:54 2007
@@ -124,7 +124,23 @@
cls.space = gettestobjspace(**{
"objspace.std.withsmartresizablelist": True})
+
+def _set_chunk_size_bits(bits):
+ from pypy.conftest import option
+ if not option.runappdirect:
+ from pypy.objspace.std import listmultiobject
+ old_value = listmultiobject.CHUNK_SIZE_BITS
+ listmultiobject.CHUNK_SIZE_BITS = bits
+ listmultiobject.CHUNK_SIZE = 2**bits
+ return old_value
+ return -1
+
class AppTest_ChunkListObject(test_listobject.AppTestW_ListObject):
+
def setup_class(cls):
cls.space = gettestobjspace(**{"objspace.std.withchunklist": True})
+ cls.chunk_size_bits = _set_chunk_size_bits(2)
+
+ def teardown_class(cls):
+ _set_chunk_size_bits(cls.chunk_size_bits)
More information about the Pypy-commit
mailing list