Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87d0b45

Browse files
Issue #15381: Optimized io.BytesIO to make less allocations and copyings.
1 parent 83e8027 commit 87d0b45

4 files changed

Lines changed: 159 additions & 189 deletions

File tree

Doc/whatsnew/3.5.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ The following performance enhancements have been added:
362362
The speed up can range from 3x to 15x.
363363
(:issue:`21486`, :issue:`21487`, :issue:`20826`)
364364

365+
* Many operations on :class:`io.BytesIO` are now 50% to 100% faster.
366+
(Contributed by Serhiy Storchaka in :issue:`15381`.)
367+
365368

366369
Build and C API Changes
367370
=======================

Lib/test/test_memoryio.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,12 +718,11 @@ def test_setstate(self):
718718

719719
@support.cpython_only
720720
def test_sizeof(self):
721-
basesize = support.calcobjsize('P2nN2PnP')
721+
basesize = support.calcobjsize('P2n2Pn')
722722
check = self.check_sizeof
723723
self.assertEqual(object.__sizeof__(io.BytesIO()), basesize)
724724
check(io.BytesIO(), basesize )
725-
check(io.BytesIO(b'a'), basesize + 1 )
726-
check(io.BytesIO(b'a' * 1000), basesize + 1000)
725+
check(io.BytesIO(b'a' * 1000), basesize + sys.getsizeof(b'a' * 1000))
727726

728727
# Various tests of copy-on-write behaviour for BytesIO.
729728

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ Core and Builtins
232232
Library
233233
-------
234234

235+
- Issue #15381: Optimized io.BytesIO to make less allocations and copyings.
236+
235237
- Issue #22818: Splitting on a pattern that could match an empty string now
236238
raises a warning. Patterns that can only match empty strings are now
237239
rejected.

0 commit comments

Comments
 (0)