mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Make levenshtein implementation faster for equal strings
This commit is contained in:
parent
c3905938ea
commit
ad5b5c740b
@ -66,12 +66,11 @@ def get_ratio(old, new):
|
||||
Returns a "similiarity ratio" representing the similarity between the two
|
||||
strings where 0 is equal and anything above less than equal.
|
||||
"""
|
||||
if old == new:
|
||||
return 0
|
||||
ratio = levenshtein_distance(old, new) / (len(old) / 100.0)
|
||||
return ratio
|
||||
return levenshtein_distance(old, new) / (len(old) / 100.0)
|
||||
|
||||
def levenshtein_distance(a, b):
|
||||
if a == b:
|
||||
return 0
|
||||
if len(a) < len(b):
|
||||
a, b = b, a
|
||||
if not a:
|
||||
|
Loading…
Reference in New Issue
Block a user