◐ Shell
clean mode source ↗

gh-107369: Optimise ``textwrap.indent()`` by AA-Turner · Pull Request #131923 · python/cpython

Conversation

@AA-Turner

@AA-Turner AA-Turner commented

Mar 31, 2025

edited by bedevere-app Bot

Loading

Follow-up to #131919, I noticed there was opportunity for improvement here too, a ~30% speed-up.

Benchmark textwrap new
indent 3.59 ms 2.81 ms: 1.28x faster

Benchmarked by indenting the contents of Objects/unicodeobject.c.

A

picnixz

Choose a reason for hiding this comment

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

@AA-Turner

Oh, I didn't see that PR! I think the optimisation is worth it, it's a small change and a reasonable speed-up for the default case (predicate=None). I'll give you co-authored-by credit!

A

methane

@@ -0,0 +1,2 @@
Improved performance of :func:`textwrap.dedent` by an average of ~1.3x.

Choose a reason for hiding this comment

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

s/dedent/indent/