diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 29ad1294e40..721efe54289 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -142,6 +142,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 diff --git a/lucene/core/src/java/org/apache/lucene/search/PrefixQuery.java b/lucene/core/src/java/org/apache/lucene/search/PrefixQuery.java index f4b5e5026cf..84ae8deae6f 100644 --- a/lucene/core/src/java/org/apache/lucene/search/PrefixQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/PrefixQuery.java @@ -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= 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); } }