FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-130167: Improve speed of `difflib.IS_LINE_JUNK` by replacing `re` by donbarbos · Pull Request #130170 · python/cpython · GitHub

/ cpython Public
12 changes: 7 additions & 5 deletions Lib/difflib.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,9 @@ def _qformat(self, aline, bline, atags, btags):
# remaining is that perhaps it was really the case that " volatile"
# was inserted after "private". I can live with that <wink>.

import re

def IS_LINE_JUNK(line, pat=re.compile(r"\s*(?:#\s*)?$").match):
def IS_LINE_JUNK(line, pat=None):
r"""
Return True for ignorable line: iff `line` is blank or contains a single '#'.
Return True for ignorable line: if `line` is blank or contains a single '#'.
Comment thread
donbarbos marked this conversation as resolved.

Examples:

Expand All @@ -1054,6 +1052,11 @@ def IS_LINE_JUNK(line, pat=re.compile(r"\s*(?:#\s*)?$").match):
False
"""

if pat is None:
# Default: match '#' or the empty string
return line.strip() in '#'
Comment thread
AA-Turner marked this conversation as resolved.
# Previous versions used the undocumented parameter 'pat' as a
# match function. Retain this behaviour for compatibility.
return pat(line) is not None

def IS_CHARACTER_JUNK(ch, ws=" \t"):
Expand Down Expand Up @@ -2027,7 +2030,6 @@ def make_table(self,fromlines,tolines,fromdesc='',todesc='',context=False,
replace('\1','</span>'). \
replace('\t','&nbsp;')

del re

def restore(delta, which):
r"""
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve speed of :func:`difflib.IS_LINE_JUNK`. Patch by Semyon Moroz.

Back | FazBrowse Home | New Git URL