optimization: reduce number od CASes
authorAlexey Kudravtsev <cdr@intellij.com>
Tue, 14 Sep 2010 14:41:27 +0000 (18:41 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Wed, 15 Sep 2010 11:53:30 +0000 (15:53 +0400)
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/UpdateHighlightersUtil.java

index 93b0b48d1dff78293085cc6fdf8dd99a736fd1d0..03ae1d3aadba394deb998f8f124ce5fa43efa8a3 100644 (file)
@@ -59,6 +59,7 @@ import org.jetbrains.annotations.TestOnly;
 import java.awt.*;
 import java.util.*;
 import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 public class UpdateHighlightersUtil {
   private static final Comparator<HighlightInfo> BY_START_OFFSET_NODUPS = new Comparator<HighlightInfo>() {
@@ -381,12 +382,13 @@ public class UpdateHighlightersUtil {
 
         if (ranges2markersCache != null) ranges2markersCache.put(new TextRange(infoStartOffset, finalInfoEndOffset), info.highlighter);
         if (info.quickFixActionRanges != null) {
-          info.quickFixActionMarkers = ContainerUtil.createEmptyCOWList();
+          List<Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker>> list = new ArrayList<Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker>>(info.quickFixActionRanges.size());
           for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
             TextRange textRange = pair.second;
             RangeMarker marker = getOrCreate(document, ranges2markersCache, textRange);
-            info.quickFixActionMarkers.add(Pair.create(pair.first, marker));
+            list.add(Pair.create(pair.first, marker));
           }
+          info.quickFixActionMarkers = new CopyOnWriteArrayList<Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker>>(list);
         }
         info.fixMarker = getOrCreate(document, ranges2markersCache, new TextRange(info.fixStartOffset, info.fixEndOffset));
       }