[
https://issues.apache.org/jira/browse/LUCENE-8047?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16247757#comment-16247757
]
Uwe Schindler commented on LUCENE-8047:
---------------------------------------
I agree with Robert. The strings here are all final constants and there is no
need to use equals - in fact the reference comparison is wanted here. The token
type is used like an enum and should always only be the constants given in the
tokenizer/filter. The question/issue we have seen here was raised quite often,
because some code quality tools complain. But Lucene is very low-level and
performance-critatical code, so the developers are aware of the consequences.
In earlier versions (before 4.0) this pattern was much more often used for
"field names", as this was a ongoing comparison (did field name change while
iterating over terms). Lucene code contains more programming-antipatterns that
should be fixed in high level projects (like business code) but are done in
Lucene for performance reasons!
My last note about this one: Using equals wont make it much worse nowadays, as
the String.equals() method early exists if the references are equal.
> Comparison of String objects using == or !=
> -------------------------------------------
>
> Key: LUCENE-8047
> URL: https://issues.apache.org/jira/browse/LUCENE-8047
> Project: Lucene - Core
> Issue Type: Improvement
> Components: modules/analysis
> Affects Versions: 7.0.1
> Environment: Ubuntu 14.04.5 LTS
> Reporter: song
> Priority: Minor
> Labels: performance
>
> My tool has scanned the whole codebase of Lucene and found there are eight
> practice issues of string comparison, in which strings are compared by using
> ==/!= instead of equals( ).
> analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
> {code:java}
> conditionPattern == SUFFIX_CONDITION_REGEX_PATTERN
> {code}
> analysis/common/src/java/org/apache/lucene/analysis/cjk/CJKBigramFilter.java
> {code:java}
> if (type == doHan || type == doHiragana || type == doKatakana || type ==
> doHangul) {
> {code}
> analysis/common/src/java/org/apache/lucene/analysis/standard/ClassicFilter.java
> {code:java}
> if (type == APOSTROPHE_TYPE &&...){
> } else if (type == ACRONYM_TYPE) {
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]