]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-129005: Avoid copy in _pyio.FileIO.readinto() (#129324)
authorCody Maloney <cmaloney@users.noreply.github.com>
Tue, 28 Jan 2025 11:40:44 +0000 (03:40 -0800)
committerGitHub <noreply@github.com>
Tue, 28 Jan 2025 11:40:44 +0000 (12:40 +0100)
commit180ee43bde99b8ce4c4f1d5237ab191e26118061
tree04b129095b05a4f778c8c1911c79b40900e7035d
parent4d0d24f6e3dff2864007c3cfd1cf7d49c6ee5317
gh-129005: Avoid copy in _pyio.FileIO.readinto() (#129324)

`os.read()` allocated and filled a buffer by calling `read(2)`, than that
data was copied into the user provied buffer. Read directly into the
caller's buffer instead by using `os.readinto()`.

`os.readinto()` uses `PyObject_GetBuffer()` to make sure the passed
in buffer is writeable and bytes-like, drop the manual check.
Lib/_pyio.py
Misc/NEWS.d/next/Library/2025-01-26-10-01-21.gh-issue-129005.ncpLvw.rst [new file with mode: 0644]