diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Stemmer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Stemmer.java index fcd998da2d0..6f5ef552cab 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Stemmer.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Stemmer.java @@ -52,14 +52,14 @@ final class Stemmer { */ public Stemmer(Dictionary dictionary) { this.dictionary = dictionary; + prefixReader = dictionary.prefixes == null ? null : dictionary.prefixes.getBytesReader(); + suffixReader = dictionary.suffixes == null ? null : dictionary.suffixes.getBytesReader(); for (int level = 0; level < 3; level++) { if (dictionary.prefixes != null) { prefixArcs[level] = new FST.Arc<>(); - prefixReaders[level] = dictionary.prefixes.getBytesReader(); } if (dictionary.suffixes != null) { suffixArcs[level] = new FST.Arc<>(); - suffixReaders[level] = dictionary.suffixes.getBytesReader(); } } formStep = dictionary.formStep(); @@ -252,13 +252,12 @@ final class Stemmer { } // some state for traversing FSTs - private final FST.BytesReader[] prefixReaders = new FST.BytesReader[3]; + private final FST.BytesReader prefixReader; + private final FST.BytesReader suffixReader; @SuppressWarnings({"unchecked", "rawtypes"}) private final FST.Arc[] prefixArcs = new FST.Arc[3]; - private final FST.BytesReader[] suffixReaders = new FST.BytesReader[3]; - @SuppressWarnings({"unchecked", "rawtypes"}) private final FST.Arc[] suffixArcs = new FST.Arc[3]; @@ -302,7 +301,6 @@ final class Stemmer { if (doPrefix && dictionary.prefixes != null) { FST fst = dictionary.prefixes; - FST.BytesReader bytesReader = prefixReaders[recursionDepth]; FST.Arc arc = prefixArcs[recursionDepth]; fst.getFirstArc(arc); IntsRef NO_OUTPUT = fst.outputs.getNoOutput(); @@ -311,7 +309,7 @@ final class Stemmer { for (int i = 0; i < limit; i++) { if (i > 0) { int ch = word[i - 1]; - if (fst.findTargetArc(ch, arc, arc, bytesReader) == null) { + if (fst.findTargetArc(ch, arc, arc, prefixReader) == null) { break; } else if (arc.output() != NO_OUTPUT) { output = fst.outputs.add(output, arc.output()); @@ -351,7 +349,6 @@ final class Stemmer { if (doSuffix && dictionary.suffixes != null) { FST fst = dictionary.suffixes; - FST.BytesReader bytesReader = suffixReaders[recursionDepth]; FST.Arc arc = suffixArcs[recursionDepth]; fst.getFirstArc(arc); IntsRef NO_OUTPUT = fst.outputs.getNoOutput(); @@ -360,7 +357,7 @@ final class Stemmer { for (int i = length; i >= limit; i--) { if (i < length) { int ch = word[i]; - if (fst.findTargetArc(ch, arc, arc, bytesReader) == null) { + if (fst.findTargetArc(ch, arc, arc, suffixReader) == null) { break; } else if (arc.output() != NO_OUTPUT) { output = fst.outputs.add(output, arc.output());