From 51c7fc9f7301892e01eb0464dd8d26b96bec2e46 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 21 Mar 2017 16:20:03 +0100 Subject: [PATCH] Don't use UserDataHolder in SlicedMapImpl, use KeyFMap directly --- .../kotlin/util/slicedMap/SlicedMapImpl.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/util/slicedMap/SlicedMapImpl.java b/compiler/frontend/src/org/jetbrains/kotlin/util/slicedMap/SlicedMapImpl.java index 4c86d9e2cfb..1682b55244c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/util/slicedMap/SlicedMapImpl.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/util/slicedMap/SlicedMapImpl.java @@ -20,7 +20,7 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Multimap; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.UserDataHolder; +import com.intellij.util.keyFMap.KeyFMap; import gnu.trove.THashMap; import kotlin.jvm.functions.Function3; import org.jetbrains.annotations.NotNull; @@ -35,7 +35,7 @@ public class SlicedMapImpl implements MutableSlicedMap { return new SlicedMapImpl(); } - private final Map map = new THashMap(0); + private final Map map = new THashMap(0); private Multimap, Object> collectiveSliceKeys = null; @Override @@ -44,17 +44,16 @@ public class SlicedMapImpl implements MutableSlicedMap { return; } - UserDataHolderImpl holder = map.get(key); + KeyFMap holder = map.get(key); if (holder == null) { - holder = new UserDataHolderImpl(); - map.put(key, holder); + holder = KeyFMap.EMPTY_MAP; } Key sliceKey = slice.getKey(); RewritePolicy rewritePolicy = slice.getRewritePolicy(); if (rewritePolicy.rewriteProcessingNeeded(key)) { - V oldValue = holder.getUserData(sliceKey); + V oldValue = holder.get(sliceKey); if (oldValue != null) { //noinspection unchecked if (!rewritePolicy.processRewrite(slice, key, oldValue, value)) { @@ -71,7 +70,7 @@ public class SlicedMapImpl implements MutableSlicedMap { collectiveSliceKeys.put(slice, key); } - holder.putUserData(sliceKey, value); + map.put(key, holder.plus(sliceKey, value)); slice.afterPut(this, key, value); } @@ -83,9 +82,9 @@ public class SlicedMapImpl implements MutableSlicedMap { @Override public V get(ReadOnlySlice slice, K key) { - UserDataHolderImpl holder = map.get(key); + KeyFMap holder = map.get(key); - V value = holder == null ? null : holder.getUserData(slice.getKey()); + V value = holder == null ? null : holder.get(slice.getKey()); return slice.computeValue(this, key, value, value == null); } @@ -101,14 +100,14 @@ public class SlicedMapImpl implements MutableSlicedMap { @Override public void forEach(@NotNull Function3 f) { - for (Map.Entry entry : map.entrySet()) { + for (Map.Entry entry : map.entrySet()) { Object key = entry.getKey(); - UserDataHolderImpl holder = entry.getValue(); + KeyFMap holder = entry.getValue(); if (holder == null) continue; for (Key sliceKey : holder.getKeys()) { - Object value = holder.getUserData(sliceKey); + Object value = holder.get(sliceKey); f.invoke(((AbstractWritableSlice) sliceKey).getSlice(), key, value); } @@ -120,11 +119,11 @@ public class SlicedMapImpl implements MutableSlicedMap { public ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice) { ImmutableMap.Builder builder = ImmutableMap.builder(); - for (Map.Entry entry : map.entrySet()) { + for (Map.Entry entry : map.entrySet()) { - UserDataHolder holder = entry.getValue(); + KeyFMap holder = entry.getValue(); - V value = holder.getUserData(slice.getKey()); + V value = holder.get(slice.getKey()); if (value != null) { //noinspection unchecked