From 75fd011e4544f0c15fe5d19cbd5a34b731e8311a Mon Sep 17 00:00:00 2001 From: "d.grigonis" Date: Mon, 23 Feb 2026 03:02:15 +0200 Subject: [PATCH] re-use calculated ratio --- Lib/difflib.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Lib/difflib.py b/Lib/difflib.py index 7c7e233b013a76..8f3cdaed9564d8 100644 --- a/Lib/difflib.py +++ b/Lib/difflib.py @@ -942,10 +942,12 @@ def _fancy_replace(self, a, alo, ahi, b, blo, bhi): cruncher.set_seq1(a[i]) # Ordering by cheapest to most expensive ratio is very # valuable, most often getting out early. - if (crqr() > best_ratio - and cqr() > best_ratio - and cr() > best_ratio): - best_i, best_j, best_ratio = i, j, cr() + if crqr() <= best_ratio or cqr() <= best_ratio: + continue + + ratio = cr() + if ratio > best_ratio: + best_i, best_j, best_ratio = i, j, ratio if best_i is None: # found nothing to synch on yet - move to next j