]> source.dussan.org Git - sonarqube.git/commitdiff
Use CompactMap instead of HashMap for Measures
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 30 Jul 2019 20:45:06 +0000 (15:45 -0500)
committerSonarTech <sonartech@sonarsource.com>
Wed, 4 Sep 2019 18:21:04 +0000 (20:21 +0200)
server/sonar-ce-task-projectanalysis/build.gradle
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java

index b801b25a6842d810f6a2ea694b2800072682fd3e..97914e8b00b09b281bc5c8bb8b6324afbcc370c3 100644 (file)
@@ -30,6 +30,7 @@ dependencies {
   compile 'com.googlecode.java-diff-utils:diffutils'
   compile 'org.mybatis:mybatis'
   compile 'org.picocontainer:picocontainer'
+  compile 'com.github.vlsi.compactmap:compactmap:1.3.0'
   
   compile project(':sonar-core')
   compile project(':server:sonar-ce-task')
index ee8b6207b656ae93ad85fd121ba655f62fc617c0..36bc9643707ce74d5a10c479a51b6565bc11902e 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.ce.task.projectanalysis.measure;
 import com.google.common.collect.ImmutableSetMultimap;
 import com.google.common.collect.SetMultimap;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
@@ -33,6 +32,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.sonar.ce.task.projectanalysis.component.Component;
 import org.sonar.ce.task.projectanalysis.metric.Metric;
+import vlsi.utils.CompactHashMap;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.lang.String.format;
@@ -44,7 +44,7 @@ import static java.util.Objects.requireNonNull;
  */
 public final class MapBasedRawMeasureRepository<T> implements MeasureRepository {
   private final Function<Component, T> componentToKey;
-  private final Map<T, Map<MeasureKey, Measure>> measures = new HashMap<>();
+  private final Map<T, Map<MeasureKey, Measure>> measures = new CompactHashMap<>();
 
   public MapBasedRawMeasureRepository(Function<Component, T> componentToKey) {
     this.componentToKey = requireNonNull(componentToKey);
@@ -152,7 +152,7 @@ public final class MapBasedRawMeasureRepository<T> implements MeasureRepository
     requireNonNull(overridePolicy);
 
     T componentKey = componentToKey.apply(component);
-    Map<MeasureKey, Measure> measuresPerMetric = measures.computeIfAbsent(componentKey, key -> new HashMap<>());
+    Map<MeasureKey, Measure> measuresPerMetric = measures.computeIfAbsent(componentKey, key -> new CompactHashMap<>());
     MeasureKey key = new MeasureKey(metric.getKey());
     if (!measuresPerMetric.containsKey(key) || overridePolicy == OverridePolicy.OVERRIDE) {
       measuresPerMetric.put(key, measure);