Skip to content
New issue

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

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

Already on GitHub? # to your account

gh-129005: Avoid copy in _pyio.FileIO.readinto #129324

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

cmaloney
Copy link
Contributor

@cmaloney cmaloney commented Jan 26, 2025

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.

`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.
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner vstinner merged commit 180ee43 into python:main Jan 28, 2025
44 checks passed
@vstinner
Copy link
Member

Merged, thank you.

@cmaloney cmaloney deleted the cmaloney/pyio_to_os_readinto branch January 28, 2025 17:34
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants