Skip to content

Commit 2a91e8d

Browse files
committed
[optimize] We only need a single instance of FindOptimizable
1 parent 9e3e65c commit 2a91e8d

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

exist-core/src/main/java/org/exist/xquery/Optimizer.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class Optimizer extends DefaultExpressionVisitor {
5757

5858
private final XQueryContext context;
5959
private final List<QueryRewriter> rewriters;
60+
private final FindOptimizable findOptimizable = new FindOptimizable();
6061

6162
private int predicates = 0;
6263

@@ -98,15 +99,16 @@ public void visitLocationStep(final LocationStep locationStep) {
9899
// walk through the predicates attached to the current location step.
99100
// try to find a predicate containing an expression which is an instance
100101
// of Optimizable.
101-
final FindOptimizable find = new FindOptimizable();
102102
for (final Predicate pred : preds) {
103-
pred.accept(find);
104-
@Nullable final Optimizable[] list = find.getOptimizables();
103+
pred.accept(findOptimizable);
104+
@Nullable final Optimizable[] list = findOptimizable.getOptimizables();
105105
if (canOptimize(list)) {
106106
optimize = true;
107+
}
108+
findOptimizable.reset();
109+
if (optimize) {
107110
break;
108111
}
109-
find.reset();
110112
}
111113
}
112114

@@ -214,16 +216,19 @@ private boolean hasOptimizable(final List<Predicate> preds) {
214216
// walk through the predicates attached to the current location step.
215217
// try to find a predicate containing an expression which is an instance
216218
// of Optimizable.
217-
final FindOptimizable find = new FindOptimizable();
219+
boolean optimizable = false;
218220
for (final Predicate pred : preds) {
219-
pred.accept(find);
220-
@Nullable final Optimizable[] list = find.getOptimizables();
221+
pred.accept(findOptimizable);
222+
@Nullable final Optimizable[] list = findOptimizable.getOptimizables();
221223
if (canOptimize(list)) {
222-
return true;
224+
optimizable = true;
225+
}
226+
findOptimizable.reset();
227+
if (optimizable) {
228+
break;
223229
}
224-
find.reset();
225230
}
226-
return false;
231+
return optimizable;
227232
}
228233

229234
@Override
@@ -433,7 +438,7 @@ private void addOptimizable(final Optimizable optimizable) {
433438
* Clears the known {@link #optimizables}.
434439
*/
435440
public void reset() {
436-
optimizables = null;
441+
this.optimizables = null;
437442
}
438443
}
439444

0 commit comments

Comments
 (0)