Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-129005: Remove copy in _pyio.FileIO.readall() #129496

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ def readall(self):
bytes_read += n

del result[bytes_read:]
return bytes(result)
return result

def readinto(self, buffer):
"""Same as RawIOBase.readinto()."""
Expand Down
6 changes: 2 additions & 4 deletions Lib/test/test_largefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ class TestFileMethods(LargeFileTest):
(i.e. > 2 GiB) files.
"""

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

@bigmemtest(size=size, memuse=2, dry_run=False)
@bigmemtest(size=size, memuse=1, dry_run=False)
def test_seek_readall(self, _size):
# Seek which doesn't change position should readall successfully.
with self.open(TESTFN, 'rb') as f:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`!_pyio`: Return bytearray from ``_pyio.FileIO.readall()`` rather than
copying into a bytes. Memory usage now matches ``_io.FileIO.readall()``
Loading