Skip to content

Commit 1379566

Browse files
committed
strip seems to give an extremely minor performance boost over lstrip
1 parent 27fcf53 commit 1379566

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Lib/textwrap.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,16 +427,15 @@ def dedent(text):
427427
428428
Entirely blank lines are normalized to a newline character.
429429
"""
430-
# Fast paths for empty or simple text
431430
if not text:
432431
return text
433432

434433
lines = text.split("\n")
435434

436-
margin = os.path.commonprefix([line for line in lines if line.lstrip()])
435+
margin = os.path.commonprefix([line for line in lines if line.strip()])
437436
margin_len = len(margin) - len(margin.lstrip())
438437

439-
return "\n".join([line[margin_len:] if line.lstrip() else "\n" if line and line[-1] == "\n" else "" for line in lines])
438+
return "\n".join([line[margin_len:] if line.strip() else "\n" if line and line[-1] == "\n" else "" for line in lines])
440439

441440

442441
def indent(text, prefix, predicate=None):

0 commit comments

Comments
 (0)