FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-157710: Defer allocation in PyUnicodeWriter_Create() by vstinner · Pull Request #157969 · python/cpython · GitHub

Repository navigation

gh-157710: Defer allocation in PyUnicodeWriter_Create() - #157969

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:writer_defer_alloc
Sep 23, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:writer_defer_alloc

Conversation

vstinner commented Sep 22, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

PyUnicodeWriter_Create(length) no longer allocates 'length' characters immediately. The allocation of the buffer is now done lazily at the first write, except if the read-only optimization is used. So the read-only optimization can also be used even if length is greater than 0.

No longer overallocate the first buffer (at the first write). Only overallocate when the buffer is resized (at the second write). It avoids the need to truncate in PyUnicodeWriter_Finish() when PyUnicodeWriter_Create(length) used the exact output length.

Add get_buffer() method to writer tests.

PyUnicodeWriter_Create(length) no longer allocates 'length'
characters immediately. The allocation of the buffer is now done
lazily at the first write, except if the read-only optimization is
used. So the read-only optimization can also be used even if length
is greater than 0.

No longer overallocate the first buffer (at the first write).
Only overallocate when the buffer is resized (at the second write).
It avoids the need to truncate in PyUnicodeWriter_Finish() when
PyUnicodeWriter_Create(length) used the exact output length.

Add get_buffer() method to writer tests.
vstinner merged commit 71f6c00 into python:main Sep 23, 2026
56 checks passed
vstinner deleted the writer_defer_alloc branch September 23, 2026 09:20
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL