LUCENE-10452: Hunspell: call checkCanceled less frequently to reduce the overhead (#723)

This commit is contained in:
Peter Gromov 2022-03-16 09:04:08 +01:00 committed by GitHub
parent 6b7953b8ce
commit af97c5ef37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -77,8 +77,6 @@ class GeneratingSuggester {
Math.max(1, word.length() - 4), Math.max(1, word.length() - 4),
word.length() + 4, word.length() + 4,
(rootChars, forms) -> { (rootChars, forms) -> {
speller.checkCanceled.run();
assert rootChars.length > 0; assert rootChars.length > 0;
if (Math.abs(rootChars.length - word.length()) > MAX_ROOT_LENGTH_DIFF) { if (Math.abs(rootChars.length - word.length()) > MAX_ROOT_LENGTH_DIFF) {
assert rootChars.length < word.length(); // processAllWords takes care of longer keys assert rootChars.length < word.length(); // processAllWords takes care of longer keys
@ -105,6 +103,8 @@ class GeneratingSuggester {
return; return;
} }
speller.checkCanceled.run();
String root = rootChars.toString(); String root = rootChars.toString();
do { do {
roots.add(new Weighted<>(new Root<>(root, forms.ints[forms.offset + suitable]), sc)); roots.add(new Weighted<>(new Root<>(root, forms.ints[forms.offset + suitable]), sc));

View File

@ -400,9 +400,10 @@ public class Hunspell {
char[] wordChars, int offset, int length, List<IntsRef> words) { char[] wordChars, int offset, int length, List<IntsRef> words) {
if (words.size() >= 100) return false; if (words.size() >= 100) return false;
checkCanceled.run();
int limit = length - dictionary.compoundMin + 1; int limit = length - dictionary.compoundMin + 1;
for (int breakPos = dictionary.compoundMin; breakPos < limit; breakPos++) { for (int breakPos = dictionary.compoundMin; breakPos < limit; breakPos++) {
checkCanceled.run();
IntsRef forms = dictionary.lookupWord(wordChars, offset, breakPos); IntsRef forms = dictionary.lookupWord(wordChars, offset, breakPos);
if (forms != null) { if (forms != null) {
words.add(forms); words.add(forms);