mirror of https://github.com/apache/lucene.git
LUCENE-7406: Automaton and PrefixQuery tweaks (fewer object (re)allocations).
This commit is contained in:
parent
d5a7ca79f3
commit
0583e5aa47
|
@ -159,6 +159,9 @@ Optimizations
|
|||
* LUCENE-7396, LUCENE-7399: Faster flush of points.
|
||||
(Adrien Grand, Mike McCandless)
|
||||
|
||||
* LUCENE-7406: Automaton and PrefixQuery tweaks (fewer object (re)allocations).
|
||||
(Christine Poerschke)
|
||||
|
||||
Other
|
||||
|
||||
* LUCENE-4787: Fixed some highlighting javadocs. (Michael Dodsworth via Adrien
|
||||
|
|
|
@ -41,7 +41,8 @@ public class PrefixQuery extends AutomatonQuery {
|
|||
|
||||
/** Build an automaton accepting all terms with the specified prefix. */
|
||||
public static Automaton toAutomaton(BytesRef prefix) {
|
||||
Automaton automaton = new Automaton();
|
||||
final int numStatesAndTransitions = prefix.length+1;
|
||||
final Automaton automaton = new Automaton(numStatesAndTransitions, numStatesAndTransitions);
|
||||
int lastState = automaton.createState();
|
||||
for(int i=0;i<prefix.length;i++) {
|
||||
int state = automaton.createState();
|
||||
|
@ -66,7 +67,7 @@ public class PrefixQuery extends AutomatonQuery {
|
|||
StringBuilder buffer = new StringBuilder();
|
||||
if (!getField().equals(field)) {
|
||||
buffer.append(getField());
|
||||
buffer.append(":");
|
||||
buffer.append(':');
|
||||
}
|
||||
buffer.append(term.text());
|
||||
buffer.append('*');
|
||||
|
|
|
@ -357,13 +357,13 @@ public class Automaton implements Accountable {
|
|||
}
|
||||
|
||||
private void growStates() {
|
||||
if (nextState+2 >= states.length) {
|
||||
if (nextState+2 > states.length) {
|
||||
states = ArrayUtil.grow(states, nextState+2);
|
||||
}
|
||||
}
|
||||
|
||||
private void growTransitions() {
|
||||
if (nextTransition+3 >= transitions.length) {
|
||||
if (nextTransition+3 > transitions.length) {
|
||||
transitions = ArrayUtil.grow(transitions, nextTransition+3);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue