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

[WIP] gh-132166: Add check in find_longest_match for checking if sequences are identical by jurgenwigg · Pull Request #132167 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 6 additions & 0 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 @@ -365,6 +365,12 @@ def find_longest_match(self, alo=0, ahi=None, blo=0, bhi=None):
ahi = len(a)
if bhi is None:
bhi = len(b)

# Check if both sequences are the same before executing rest of the
# method.
if a[alo:ahi] == b[blo:bhi]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is this covered in tests? if not, please add a test, otherwise no need to add a large one.

return Match(alo, blo, len(a[alo:ahi]))

besti, bestj, bestsize = alo, blo, 0
# find longest junk-free match
# during an iteration of the loop, j2len[j] = length of longest
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,5 @@
Add checking if sequences ``a[alo:ahi]`` and ``b[blo:bhi]`` are the same on the
beginning of the method find_longest_match in SequenceMatcher. For identical
sequences there is no reason to run whole logic when simple check can be done.
Comment on lines +1 to +3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This NEWS should be summarized. I suggest something like (assumiong that the method is documented, if not use a plain

Add a fast path in :meth:`SequenceMatcher.find_longest_match
<difflib.SequenceMatcher.find_longest_match>` to handle the
case when ``a[alo:ahi] == b[blo:bhi]``.

It appears to fix issue when comparing two slightly different strings ends up
with waiting forever for the result.
Comment on lines +4 to +5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
It appears to fix issue when comparing two slightly different strings ends up
with waiting forever for the result.
It appears to fix issue when comparing two slightly different strings ends up
with waiting forever for the result.

We should be more confident here. Does it fix the issue or not? if so, let's say it. Otherwise, let's not give tentative conclusions.


Back | FazBrowse Home | New Git URL