diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 31a572a54..c169e0a62 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -7585,6 +7585,10 @@ distance is O(nm), but a bound of k allows us to reduce it to O(km) time by only } else if (m == 0) { return n <= threshold ? n : -1; } + // no need to calculate the distance if the length difference is greater than the threshold + else if (Math.abs(n - m) > threshold) { + return -1; + } if (n > m) { // swap the two strings to consume less memory