Optimize TimeExtractionTopNAlgorithm (#9336)

When the time extraction Top N algorithm is looking for aggregators, it makes
2 calls to hashCode on the key. Use Map#computeIfAbsent instead so that the
hashCode is calculated only once
This commit is contained in:
Suneet Saldanha 2020-02-10 14:26:10 -08:00 committed by GitHub
parent 51d7864935
commit ea006dc72a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -98,11 +98,10 @@ public class TimeExtractionTopNAlgorithm extends BaseTopNAlgorithm<int[], Map<Co
while (!cursor.isDone()) {
final Comparable<?> key = dimensionValueConverter.apply(dimSelector.lookupName(dimSelector.getRow().get(0)));
Aggregator[] theAggregators = aggregatesStore.get(key);
if (theAggregators == null) {
theAggregators = makeAggregators(cursor, query.getAggregatorSpecs());
aggregatesStore.put(key, theAggregators);
}
Aggregator[] theAggregators = aggregatesStore.computeIfAbsent(
key,
k -> makeAggregators(cursor, query.getAggregatorSpecs())
);
for (Aggregator aggregator : theAggregators) {
aggregator.aggregate();