LUCENE-7406: Automaton and PrefixQuery tweaks (fewer object (re)allocations).

This commit is contained in:
Christine Poerschke 2016-08-05 12:13:37 +01:00
parent d5a7ca79f3
commit 0583e5aa47
3 changed files with 8 additions and 4 deletions

View File

@ -159,6 +159,9 @@ Optimizations
* LUCENE-7396, LUCENE-7399: Faster flush of points. * LUCENE-7396, LUCENE-7399: Faster flush of points.
(Adrien Grand, Mike McCandless) (Adrien Grand, Mike McCandless)
* LUCENE-7406: Automaton and PrefixQuery tweaks (fewer object (re)allocations).
(Christine Poerschke)
Other Other
* LUCENE-4787: Fixed some highlighting javadocs. (Michael Dodsworth via Adrien * LUCENE-4787: Fixed some highlighting javadocs. (Michael Dodsworth via Adrien

View File

@ -41,7 +41,8 @@ public class PrefixQuery extends AutomatonQuery {
/** Build an automaton accepting all terms with the specified prefix. */ /** Build an automaton accepting all terms with the specified prefix. */
public static Automaton toAutomaton(BytesRef 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(); int lastState = automaton.createState();
for(int i=0;i<prefix.length;i++) { for(int i=0;i<prefix.length;i++) {
int state = automaton.createState(); int state = automaton.createState();
@ -66,7 +67,7 @@ public class PrefixQuery extends AutomatonQuery {
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
if (!getField().equals(field)) { if (!getField().equals(field)) {
buffer.append(getField()); buffer.append(getField());
buffer.append(":"); buffer.append(':');
} }
buffer.append(term.text()); buffer.append(term.text());
buffer.append('*'); buffer.append('*');

View File

@ -357,13 +357,13 @@ public class Automaton implements Accountable {
} }
private void growStates() { private void growStates() {
if (nextState+2 >= states.length) { if (nextState+2 > states.length) {
states = ArrayUtil.grow(states, nextState+2); states = ArrayUtil.grow(states, nextState+2);
} }
} }
private void growTransitions() { private void growTransitions() {
if (nextTransition+3 >= transitions.length) { if (nextTransition+3 > transitions.length) {
transitions = ArrayUtil.grow(transitions, nextTransition+3); transitions = ArrayUtil.grow(transitions, nextTransition+3);
} }
} }