You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2016/08/05 11:35:35 UTC
lucene-solr:master: LUCENE-7406: Automaton and PrefixQuery tweaks
(fewer object (re)allocations).
Repository: lucene-solr
Updated Branches:
refs/heads/master d5a7ca79f -> 0583e5aa4
LUCENE-7406: Automaton and PrefixQuery tweaks (fewer object (re)allocations).
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0583e5aa
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0583e5aa
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0583e5aa
Branch: refs/heads/master
Commit: 0583e5aa4719f7c7b65164435a8a7debf83f7f09
Parents: d5a7ca7
Author: Christine Poerschke <cp...@apache.org>
Authored: Fri Aug 5 12:13:37 2016 +0100
Committer: Christine Poerschke <cp...@apache.org>
Committed: Fri Aug 5 12:13:37 2016 +0100
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 +++
lucene/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(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0583e5aa/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index e83e6cb..c5db143 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
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0583e5aa/lucene/core/src/java/org/apache/lucene/search/PrefixQuery.java
----------------------------------------------------------------------
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 f4b5e50..84ae8de 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<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('*');
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0583e5aa/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java b/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
index 42f28ed..0dd449c 100644
--- a/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
+++ b/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
@@ -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);
}
}