summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-10-05 19:12:18 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-10-05 19:12:18 (GMT)
commit5df8a8a1fd6cc6f4469dc7d3994d06e2aea24c52 (patch)
tree3e56cec37fe9182adb7ae56eacdc68149dfb1981 /Lib
parentdcd01b49329d5596c3ad3254ae9eeabd15f100d2 (diff)
downloadcpython-5df8a8a1fd6cc6f4469dc7d3994d06e2aea24c52.zip
cpython-5df8a8a1fd6cc6f4469dc7d3994d06e2aea24c52.tar.gz
cpython-5df8a8a1fd6cc6f4469dc7d3994d06e2aea24c52.tar.bz2
Issue #19087: Improve bytearray allocation in order to allow cheap popping of data at the front (slice deletion).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_bytes.py9
-rw-r--r--Lib/test/test_sys.py2
2 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index f12f911..847c7a6 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -909,6 +909,15 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
with self.assertRaises(ValueError):
b[3:4] = elem
+ def test_setslice_extend(self):
+ # Exercise the resizing logic (see issue #19087)
+ b = bytearray(range(100))
+ self.assertEqual(list(b), list(range(100)))
+ del b[:10]
+ self.assertEqual(list(b), list(range(10, 100)))
+ b.extend(range(100, 110))
+ self.assertEqual(list(b), list(range(10, 110)))
+
def test_extended_set_del_slice(self):
indices = (0, None, 1, 3, 19, 300, 1<<333, -1, -2, -31, -300)
for start in indices:
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 30eca4a..70b55b2 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -721,7 +721,7 @@ class SizeofTest(unittest.TestCase):
samples = [b'', b'u'*100000]
for sample in samples:
x = bytearray(sample)
- check(x, vsize('inP') + x.__alloc__())
+ check(x, vsize('n2Pi') + x.__alloc__())
# bytearray_iterator
check(iter(bytearray()), size('nP'))
# cell