Skip to content

Commit a881837

Browse files
committed
gh-129005: Remove copy in _pyio.FileIO.readall()
This aligns the memory usage between _pyio and _io. Both now use the same amount of memory when reading a file.
1 parent 10ee2d9 commit a881837

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
@@ -1702,7 +1702,7 @@ def readall(self):
17021702
bytes_read += n
17031703

17041704
del result[bytes_read:]
1705-
return bytes(result)
1705+
return result
17061706

17071707
def readinto(self, buffer):
17081708
"""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+
:mod:`!_pyio`: Return bytearray from ``_pyio.FileIO.readall()`` rather than
2+
copying into a bytes. Memory usage now matches ``_io.FileIO.readall()``

0 commit comments

Comments
 (0)