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 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. |
|
@thejesh23 I'm sorry, I've removed the one about NEWS accidentially, thank you for addressing it in 43c0f59. That said:
Thank you! 💚 |
|
@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 ::) |
|
@serhiy-storchaka could you take a look when you have time? You worked on the long-word handling in gh-139065. |
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.