Repository navigation
Conversation
TextWrapper._handle_long_word() broke off one line's worth of a long word at a time and stored the rest back, copying the rest of the word for every line. Break the rest of the word into the pieces of all the following lines in one pass instead. They all have the same width, so the result is the same.
maurycy
reviewed
Nov 14, 2026
Contributor
Author
|
@maurycy thanks for the review I'm not sure why you have deleted your posted comment actually its a right catch , NEWS entry: use :mod: instead of naming functions. |
Contributor
|
@thejesh23 I'm sorry, I've removed the one about NEWS accidentially, thank you for addressing it in 43c0f59. That said:
Thank you! 💚 |
Contributor
Author
|
@maurycy no worries .
Actually used normal optimised build (./configure with -O3), without --enable-optimizations or --with-lto
Agree to move the splitting into _wrap_chunks().
Still getting used to the used to all of repo rules . Irrespective of repo rules for responding/acting on comments I don't use AI ::) |
maurycy
reviewed
Nov 15, 2026
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.
textwrap.wrap()took quadratic time on a long word: each line broke off one piece and copied the rest of the word.When a line after the first starts with a long word,
_wrap_chunks()now splits it into line-width pieces at once, since all those lines have the same width. Words with whitespace, or with hyphens whenbreak_on_hyphensis true, keep the old path. The output is unchanged.wrap(s, 76)wrap(s, 76)wrap(s, 76)'x' * 3_200_000,wrap(s, 70)Testing: a new test in
test_textwrap, identical output from old and new code on 260,000 random inputs, and the full test suite passes.AI disclosure: prepared with the help of Claude Code; I reviewed the change and the test results.