From 19a14cbefae99b90d5960b0e68b99c5b1ef680d5 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sun, 18 Jul 2010 12:08:21 +0000 Subject: [PATCH] A small improvement in FuzzyTermsEnum, as the ArrayList was initially allocated with one element less so internal array reallocated every time. This removes the use of ArrayList at all. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@965216 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/java/org/apache/lucene/search/FuzzyTermsEnum.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java b/lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java index b2f1fcf6197..83940381347 100644 --- a/lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java +++ b/lucene/src/java/org/apache/lucene/search/FuzzyTermsEnum.java @@ -33,7 +33,7 @@ import org.apache.lucene.util.automaton.ByteRunAutomaton; import org.apache.lucene.util.automaton.LevenshteinAutomata; import java.io.IOException; -import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.List; @@ -135,7 +135,7 @@ public final class FuzzyTermsEnum extends TermsEnum { LevenshteinAutomata builder = new LevenshteinAutomata(UnicodeUtil.newString(termText, realPrefixLength, termText.length - realPrefixLength)); - runAutomata = new ArrayList(maxDistance); + final ByteRunAutomaton[] ra = new ByteRunAutomaton[maxDistance + 1]; for (int i = 0; i <= maxDistance; i++) { Automaton a = builder.toAutomaton(i); // constant prefix @@ -144,8 +144,9 @@ public final class FuzzyTermsEnum extends TermsEnum { UnicodeUtil.newString(termText, 0, realPrefixLength)); a = BasicOperations.concatenate(prefix, a); } - runAutomata.add(new ByteRunAutomaton(a)); + ra[i] = new ByteRunAutomaton(a); } + runAutomata = Arrays.asList(ra); } }