{{ message }}
gh-141968: Use bytearray.take_bytes() in more I/O paths - #156989
Closed
methane wants to merge 1 commit into
Closed
Conversation
6 tasks
There was a problem hiding this comment.
🟢 Approval recommended
Both changes preserve return types and behavior while safely eliminating unnecessary copies from locally owned bytearrays.
Pull request overview
Uses bytearray.take_bytes() to avoid final buffer copies in I/O and ZIP decryption paths.
Changes:
- Optimizes
_IOBase.readline(). - Optimizes legacy ZIP decryption output.
File summaries
| File | Description |
|---|---|
Modules/_io/iobase.c |
Transfers the readline buffer directly into bytes. |
Lib/zipfile/__init__.py |
Transfers decrypted output directly into bytes. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
kumaraditya303
approved these changes
Sep 5, 2026
cmaloney
approved these changes
Sep 5, 2026
cmaloney
left a comment
Contributor
There was a problem hiding this comment.
👍
I had a PR for the zipfile one previously (#142240). I think it is reasonable to do but hard to benchmark (the decrypter usage is uncommon).
For .readline() it probably makes sense to move entirely to PyBytesWriter (https://peps.python.org/pep-0782/). That is a separate larger scope change though.
methane
force-pushed
the
optimize-take-bytes-io
branch
2 times, most recently
from
September 6, 2026 04:10
8de25cb to
c4f4c75
Compare
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Uh oh!
There was an error while loading. Please reload this page.