Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
strip seems to give an extremely minor performance boost over lstrip
  • Loading branch information
Marius-Juston committed Mar 28, 2025
commit 1379566463b1746a6ebc98fd548e9c8b92c8e0a4
5 changes: 2 additions & 3 deletions Lib/textwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,15 @@ def dedent(text):

Entirely blank lines are normalized to a newline character.
"""
# Fast paths for empty or simple text
if not text:
return text
Comment thread
Marius-Juston marked this conversation as resolved.

lines = text.split("\n")

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

return "\n".join([line[margin_len:] if line.lstrip() else "\n" if line and line[-1] == "\n" else "" for line in lines])
return "\n".join([line[margin_len:] if line.strip() else "\n" if line and line[-1] == "\n" else "" for line in lines])
Comment thread
Marius-Juston marked this conversation as resolved.
Outdated


def indent(text, prefix, predicate=None):
Expand Down
Loading