From f2f484680f155e89139e5651955ff057660bd2aa Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Wed, 13 Apr 2016 11:27:17 +0100 Subject: [PATCH] LUCENE-7205: Remove repeated nl.getLength() calls in (Boolean|DisjunctionMax|FuzzyLikeThis)QueryBuilder. --- lucene/CHANGES.txt | 3 +++ .../lucene/queryparser/xml/builders/BooleanQueryBuilder.java | 3 ++- .../queryparser/xml/builders/DisjunctionMaxQueryBuilder.java | 3 ++- .../queryparser/xml/builders/FuzzyLikeThisQueryBuilder.java | 3 ++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index e371f25aabb..87d039fba0d 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -84,6 +84,9 @@ Other * LUCENE-7174: Upgrade randomizedtesting to 2.3.4. (Uwe Schindler, Dawid Weiss) +* LUCENE-7205: Remove repeated nl.getLength() calls in + (Boolean|DisjunctionMax|FuzzyLikeThis)QueryBuilder. (Christine Poerschke) + ======================= Lucene 6.0.0 ======================= System Requirements diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java index 1dd859cc3ef..fbd678b08fd 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/BooleanQueryBuilder.java @@ -49,7 +49,8 @@ public class BooleanQueryBuilder implements QueryBuilder { bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e, "minimumNumberShouldMatch", 0)); NodeList nl = e.getChildNodes(); - for (int i = 0; i < nl.getLength(); i++) { + final int nlLen = nl.getLength(); + for (int i = 0; i < nlLen; i++) { Node node = nl.item(i); if (node.getNodeName().equals("Clause")) { Element clauseElem = (Element) node; diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java index 849066795f4..0dc9e05b8e3 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java @@ -49,7 +49,8 @@ public class DisjunctionMaxQueryBuilder implements QueryBuilder { List disjuncts = new ArrayList<>(); NodeList nl = e.getChildNodes(); - for (int i = 0; i < nl.getLength(); i++) { + final int nlLen = nl.getLength(); + for (int i = 0; i < nlLen; i++) { Node node = nl.item(i); if (node instanceof Element) { // all elements are disjuncts. Element queryElem = (Element) node; diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/FuzzyLikeThisQueryBuilder.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/FuzzyLikeThisQueryBuilder.java index f969a66480b..e7e9ad3cfe5 100644 --- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/FuzzyLikeThisQueryBuilder.java +++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/FuzzyLikeThisQueryBuilder.java @@ -50,7 +50,8 @@ public class FuzzyLikeThisQueryBuilder implements QueryBuilder { FuzzyLikeThisQuery fbq = new FuzzyLikeThisQuery(maxNumTerms, analyzer); fbq.setIgnoreTF(DOMUtils.getAttribute(e, "ignoreTF", DEFAULT_IGNORE_TF)); - for (int i = 0; i < nl.getLength(); i++) { + final int nlLen = nl.getLength(); + for (int i = 0; i < nlLen; i++) { Element fieldElem = (Element) nl.item(i); float minSimilarity = DOMUtils.getAttribute(fieldElem, "minSimilarity", DEFAULT_MIN_SIMILARITY); int prefixLength = DOMUtils.getAttribute(fieldElem, "prefixLength", DEFAULT_PREFIX_LENGTH);