Skip to content
Open
Changes from all commits
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
6 changes: 6 additions & 0 deletions python3/diff_match_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,8 @@ def match_bitapScore(e, x):
Returns:
Overall score for match (0.0 = good, 1.0 = bad).
"""
if (e == 0 and x == loc):
return 0.0
accuracy = float(e) / len(pattern)
proximity = abs(loc - x)
if not self.Match_Distance:
Expand All @@ -1287,10 +1289,14 @@ def match_bitapScore(e, x):
best_loc = text.find(pattern, loc)
if best_loc != -1:
score_threshold = min(match_bitapScore(0, best_loc), score_threshold)
if score_threshold == 0.0: # Can't improve this
return best_loc
# What about in the other direction? (speedup)
best_loc = text.rfind(pattern, loc + len(pattern))
if best_loc != -1:
score_threshold = min(match_bitapScore(0, best_loc), score_threshold)
if score_threshold == 0.0:
return best_loc

# Initialise the bit arrays.
matchmask = 1 << (len(pattern) - 1)
Expand Down