Skip to content

Commit 9ccf3e2

Browse files
committed
pythongh-129005: Remove copy in _pyio.FileIO.readall()
This aligns the memory usage between _pyio and _io. Both use the same amount of memory.
1 parent d0d9463 commit 9ccf3e2

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Lib/_pyio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ def readall(self):
17031703
bytes_read += n
17041704

17051705
del result[bytes_read:]
1706-
return bytes(result)
1706+
return result
17071707

17081708
def readinto(self, buffer):
17091709
"""Same as RawIOBase.readinto()."""

Lib/test/test_largefile.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ class TestFileMethods(LargeFileTest):
5656
(i.e. > 2 GiB) files.
5757
"""
5858

59-
# _pyio.FileIO.readall() uses a temporary bytearray then casted to bytes,
60-
# so memuse=2 is needed
61-
@bigmemtest(size=size, memuse=2, dry_run=False)
59+
@bigmemtest(size=size, memuse=1, dry_run=False)
6260
def test_large_read(self, _size):
6361
# bpo-24658: Test that a read greater than 2GB does not fail.
6462
with self.open(TESTFN, "rb") as f:
@@ -154,7 +152,7 @@ def test_seekable(self):
154152
f.seek(pos)
155153
self.assertTrue(f.seekable())
156154

157-
@bigmemtest(size=size, memuse=2, dry_run=False)
155+
@bigmemtest(size=size, memuse=1, dry_run=False)
158156
def test_seek_readall(self, _size):
159157
# Seek which doesn't change position should readall successfully.
160158
with self.open(TESTFN, 'rb') as f:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Return a bytearray from ``_pyio.FileIO.readall()`` which makes it require
2+
the same amount of memory as ``_io.FileIO.readall()``

0 commit comments

Comments
 (0)