hunspell GeneratingSuggester: ensure there are never more than 100 roots to process (#13154)

hunspell GeneratingSuggester: ensure there are never more than 100 roots to process
This commit is contained in:
Peter Gromov 2024-03-05 09:53:27 +01:00 committed by GitHub
parent 47792dfcd3
commit 193cc62c73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View File

@ -221,6 +221,8 @@ Bug Fixes
* GITHUB#13145: Detect MemorySegmentIndexInput correctly in NRTSuggester. (Uwe Schindler)
* GITHUB#13154: Hunspell GeneratingSuggester: ensure there are never more than 100 roots to process (Peter Gromov)
Other
---------------------

View File

@ -88,8 +88,7 @@ class GeneratingSuggester {
CharsRef rootChars = entry.root();
sc += commonPrefix(word, rootChars) - longerWorsePenalty(word.length(), rootChars.length);
boolean overflow = roots.size() == MAX_ROOTS;
if (overflow && isWorseThan(sc, rootChars, roots.peek())) {
if (roots.size() == MAX_ROOTS && isWorseThan(sc, rootChars, roots.peek())) {
return;
}
@ -100,7 +99,7 @@ class GeneratingSuggester {
for (int i = 0; i < forms.length; i++) {
if (isSuggestible.test(forms.ints[forms.offset + i])) {
roots.add(new Weighted<>(new Root<>(root, forms.ints[forms.offset + i]), sc));
if (overflow) {
if (roots.size() == MAX_ROOTS) {
roots.poll();
}
}