Apache Lucene open-source search software
LUCENE-10452: Hunspell: call checkCanceled less frequently to reduce the overhead (#723)
Peter Gromovaf97c5ef379f
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.javaindex f7ffdc3b6dd..6d999fffbf5 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java@@ -77,8 +77,6 @@ class GeneratingSuggester {Math.max(1, word.length() - 4),word.length() + 4,(rootChars, forms) -> {- speller.checkCanceled.run();-assert rootChars.length > 0;if (Math.abs(rootChars.length - word.length()) > MAX_ROOT_LENGTH_DIFF) {assert rootChars.length < word.length(); // processAllWords takes care of longer keys@@ -105,6 +103,8 @@ class GeneratingSuggester {return;}+ speller.checkCanceled.run();+String root = rootChars.toString();do {roots.add(new Weighted<>(new Root<>(root, forms.ints[forms.offset + suitable]), sc));diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Hunspell.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Hunspell.javaindex 27eebc6e3ec..329ea0addab 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Hunspell.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Hunspell.java@@ -400,9 +400,10 @@ public class Hunspell {char[] wordChars, int offset, int length, List<IntsRef> words) {if (words.size() >= 100) return false;+ checkCanceled.run();+int limit = length - dictionary.compoundMin + 1;for (int breakPos = dictionary.compoundMin; breakPos < limit; breakPos++) {- checkCanceled.run();IntsRef forms = dictionary.lookupWord(wordChars, offset, breakPos);if (forms != null) {words.add(forms);