donnerpeter commented on code in PR #11857:
URL: https://github.com/apache/lucene/pull/11857#discussion_r997349204
##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Hunspell.java:
##########
@@ -614,11 +617,27 @@ private void doSuggest(
Runnable checkCanceled) {
Hunspell suggestionSpeller =
new Hunspell(dictionary, policy, checkCanceled) {
+ final Map<String, Optional<Root<CharsRef>>> compoundCache = new
HashMap<>();
+
@Override
boolean acceptsStem(int formID) {
return !dictionary.hasFlag(formID, dictionary.noSuggest)
&& !dictionary.hasFlag(formID, dictionary.subStandard);
}
+
+ @Override
+ Root<CharsRef> findStem(
+ char[] chars, int offset, int length, WordCase originalCase,
WordContext context) {
+ if (context == COMPOUND_BEGIN && originalCase == null) {
+ return compoundCache
+ .computeIfAbsent(
+ new String(chars, offset, length),
+ __ ->
+ Optional.ofNullable(super.findStem(chars, offset,
length, null, context)))
Review Comment:
computeIfAbsent is called even if there's an associated null value. And
containsKey+get+put finds the hash entry several times
##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Hunspell.java:
##########
@@ -614,11 +617,27 @@ private void doSuggest(
Runnable checkCanceled) {
Hunspell suggestionSpeller =
new Hunspell(dictionary, policy, checkCanceled) {
+ final Map<String, Optional<Root<CharsRef>>> compoundCache = new
HashMap<>();
+
@Override
boolean acceptsStem(int formID) {
return !dictionary.hasFlag(formID, dictionary.noSuggest)
&& !dictionary.hasFlag(formID, dictionary.subStandard);
}
+
+ @Override
+ Root<CharsRef> findStem(
+ char[] chars, int offset, int length, WordCase originalCase,
WordContext context) {
+ if (context == COMPOUND_BEGIN && originalCase == null) {
+ return compoundCache
+ .computeIfAbsent(
+ new String(chars, offset, length),
+ __ ->
+ Optional.ofNullable(super.findStem(chars, offset,
length, null, context)))
Review Comment:
computeIfAbsent lambda is called even if there's an associated null value.
And containsKey+get+put finds the hash entry several times
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]