Skip to content

Commit b5ee497

Browse files
dg-pbljfp
authored andcommitted
pythongh-145131: difflib.Differ._fancy_replace performance (re-use ratio) (python#145133)
re-use calculated ratio
1 parent 7631d20 commit b5ee497

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Lib/difflib.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,10 +942,12 @@ def _fancy_replace(self, a, alo, ahi, b, blo, bhi):
942942
cruncher.set_seq1(a[i])
943943
# Ordering by cheapest to most expensive ratio is very
944944
# valuable, most often getting out early.
945-
if (crqr() > best_ratio
946-
and cqr() > best_ratio
947-
and cr() > best_ratio):
948-
best_i, best_j, best_ratio = i, j, cr()
945+
if crqr() <= best_ratio or cqr() <= best_ratio:
946+
continue
947+
948+
ratio = cr()
949+
if ratio > best_ratio:
950+
best_i, best_j, best_ratio = i, j, ratio
949951

950952
if best_i is None:
951953
# found nothing to synch on yet - move to next j

0 commit comments

Comments
 (0)