From 0583e5aa4719f7c7b65164435a8a7debf83f7f09 Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Fri, 5 Aug 2016 12:13:37 +0100 Subject: [PATCH] LUCENE-7406: Automaton and PrefixQuery tweaks (fewer object (re)allocations). --- lucene/CHANGES.txt | 3 +++ .../core/src/java/org/apache/lucene/search/PrefixQuery.java | 5 +++-- .../src/java/org/apache/lucene/util/automaton/Automaton.java | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index e83e6cba370..c5db1438d8b 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -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 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); } }