mirror of https://github.com/apache/lucene.git
Speedup OrderedIntervalsSource (#13871)
Looking up the same indices out of a list is very costly, also better keep things in local variables (likely registers) where possible.
This commit is contained in:
parent
5d5dddd103
commit
a14f9cd2eb
|
@ -124,38 +124,54 @@ class OrderedIntervalsSource extends MinimizingConjunctionIntervalsSource {
|
||||||
start = end = slop = IntervalIterator.NO_MORE_INTERVALS;
|
start = end = slop = IntervalIterator.NO_MORE_INTERVALS;
|
||||||
int lastStart = Integer.MAX_VALUE;
|
int lastStart = Integer.MAX_VALUE;
|
||||||
boolean minimizing = false;
|
boolean minimizing = false;
|
||||||
|
final var subIterators = this.subIterators;
|
||||||
|
int currentIndex = i;
|
||||||
while (true) {
|
while (true) {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (subIterators.get(i - 1).end() >= lastStart) {
|
var prev = subIterators.get(currentIndex - 1);
|
||||||
|
if (prev.end() >= lastStart) {
|
||||||
|
i = currentIndex;
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
if (i == subIterators.size()
|
if (currentIndex == subIterators.size()) {
|
||||||
|| (minimizing && subIterators.get(i).start() > subIterators.get(i - 1).end())) {
|
break;
|
||||||
|
}
|
||||||
|
final IntervalIterator current = subIterators.get(currentIndex);
|
||||||
|
if (minimizing && (current.start() > prev.end())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
if (subIterators.get(i).end() >= lastStart
|
if (current.end() >= lastStart
|
||||||
|| subIterators.get(i).nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
|
|| current.nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
|
||||||
|
i = currentIndex;
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
} while (subIterators.get(i).start() <= subIterators.get(i - 1).end());
|
} while (current.start() <= prev.end());
|
||||||
i++;
|
currentIndex++;
|
||||||
}
|
}
|
||||||
start = subIterators.get(0).start();
|
var first = subIterators.getFirst();
|
||||||
|
final int start = first.start();
|
||||||
|
this.start = start;
|
||||||
if (start == NO_MORE_INTERVALS) {
|
if (start == NO_MORE_INTERVALS) {
|
||||||
|
i = currentIndex;
|
||||||
return end = NO_MORE_INTERVALS;
|
return end = NO_MORE_INTERVALS;
|
||||||
}
|
}
|
||||||
end = subIterators.get(subIterators.size() - 1).end();
|
var last = subIterators.getLast();
|
||||||
slop = end - start + 1;
|
|
||||||
|
final int end = last.end();
|
||||||
|
this.end = end;
|
||||||
|
int slop = end - start + 1;
|
||||||
for (IntervalIterator subIterator : subIterators) {
|
for (IntervalIterator subIterator : subIterators) {
|
||||||
slop -= subIterator.width();
|
slop -= subIterator.width();
|
||||||
}
|
}
|
||||||
|
this.slop = slop;
|
||||||
onMatch.onMatch();
|
onMatch.onMatch();
|
||||||
lastStart = subIterators.get(subIterators.size() - 1).start();
|
currentIndex = 1;
|
||||||
i = 1;
|
if (first.nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
|
||||||
if (subIterators.get(0).nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
|
i = currentIndex;
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
lastStart = last.start();
|
||||||
minimizing = true;
|
minimizing = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue