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:
Armin Braun 2024-10-08 19:00:24 +02:00 committed by GitHub
parent 5d5dddd103
commit a14f9cd2eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 13 deletions

View File

@ -124,38 +124,54 @@ class OrderedIntervalsSource extends MinimizingConjunctionIntervalsSource {
start = end = slop = IntervalIterator.NO_MORE_INTERVALS;
int lastStart = Integer.MAX_VALUE;
boolean minimizing = false;
final var subIterators = this.subIterators;
int currentIndex = i;
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;
}
if (i == subIterators.size()
|| (minimizing && subIterators.get(i).start() > subIterators.get(i - 1).end())) {
if (currentIndex == subIterators.size()) {
break;
}
final IntervalIterator current = subIterators.get(currentIndex);
if (minimizing && (current.start() > prev.end())) {
break;
}
do {
if (subIterators.get(i).end() >= lastStart
|| subIterators.get(i).nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
if (current.end() >= lastStart
|| current.nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
i = currentIndex;
return start;
}
} while (subIterators.get(i).start() <= subIterators.get(i - 1).end());
i++;
} while (current.start() <= prev.end());
currentIndex++;
}
start = subIterators.get(0).start();
var first = subIterators.getFirst();
final int start = first.start();
this.start = start;
if (start == NO_MORE_INTERVALS) {
i = currentIndex;
return end = NO_MORE_INTERVALS;
}
end = subIterators.get(subIterators.size() - 1).end();
slop = end - start + 1;
var last = subIterators.getLast();
final int end = last.end();
this.end = end;
int slop = end - start + 1;
for (IntervalIterator subIterator : subIterators) {
slop -= subIterator.width();
}
this.slop = slop;
onMatch.onMatch();
lastStart = subIterators.get(subIterators.size() - 1).start();
i = 1;
if (subIterators.get(0).nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
currentIndex = 1;
if (first.nextInterval() == IntervalIterator.NO_MORE_INTERVALS) {
i = currentIndex;
return start;
}
lastStart = last.start();
minimizing = true;
}
}