mirror of https://github.com/apache/lucene.git
fix silly minor performance bug in CompiledAutomaton/Terms.intersect implementations
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1669639 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e0ff3a6b0c
commit
f49f2b2af6
|
@ -78,7 +78,8 @@ public class CompiledAutomaton {
|
|||
/**
|
||||
* Shared common suffix accepted by the automaton. Only valid
|
||||
* for {@link AUTOMATON_TYPE#NORMAL}, and only when the
|
||||
* automaton accepts an infinite language.
|
||||
* automaton accepts an infinite language. This will be null
|
||||
* if the common prefix is length 0.
|
||||
*/
|
||||
public final BytesRef commonSuffixRef;
|
||||
|
||||
|
@ -202,7 +203,12 @@ public class CompiledAutomaton {
|
|||
commonSuffixRef = null;
|
||||
} else {
|
||||
// NOTE: this is a very costly operation! We should test if it's really warranted in practice...
|
||||
commonSuffixRef = Operations.getCommonSuffixBytesRef(binary, maxDeterminizedStates);
|
||||
BytesRef suffix = Operations.getCommonSuffixBytesRef(binary, maxDeterminizedStates);
|
||||
if (suffix.length == 0) {
|
||||
commonSuffixRef = null;
|
||||
} else {
|
||||
commonSuffixRef = suffix;
|
||||
}
|
||||
}
|
||||
|
||||
// This will determinize the binary automaton for us:
|
||||
|
|
|
@ -1063,7 +1063,7 @@ final public class Operations {
|
|||
* Returns the longest string that is a prefix of all accepted strings and
|
||||
* visits each state at most once. The automaton must be deterministic.
|
||||
*
|
||||
* @return common prefix
|
||||
* @return common prefix, which can be an empty (length 0) String (never null)
|
||||
*/
|
||||
public static String getCommonPrefix(Automaton a) {
|
||||
if (a.isDeterministic() == false) {
|
||||
|
@ -1097,7 +1097,7 @@ final public class Operations {
|
|||
* Returns the longest BytesRef that is a prefix of all accepted strings and
|
||||
* visits each state at most once. The automaton must be deterministic.
|
||||
*
|
||||
* @return common prefix
|
||||
* @return common prefix, which can be an empty (length 0) BytesRef (never null)
|
||||
*/
|
||||
public static BytesRef getCommonPrefixBytesRef(Automaton a) {
|
||||
BytesRefBuilder builder = new BytesRefBuilder();
|
||||
|
@ -1159,7 +1159,7 @@ final public class Operations {
|
|||
* @param maxDeterminizedStates maximum number of states determinizing the
|
||||
* automaton can result in. Set higher to allow more complex queries and
|
||||
* lower to prevent memory exhaustion.
|
||||
* @return common suffix
|
||||
* @return common suffix, which can be an empty (length 0) BytesRef (never null)
|
||||
*/
|
||||
public static BytesRef getCommonSuffixBytesRef(Automaton a, int maxDeterminizedStates) {
|
||||
// reverse the language of the automaton, then reverse its common prefix.
|
||||
|
|
Loading…
Reference in New Issue