Don't use UserDataHolder in SlicedMapImpl, use KeyFMap directly
This commit is contained in:
@@ -20,7 +20,7 @@ import com.google.common.collect.ArrayListMultimap;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.intellij.openapi.util.Key;
|
import com.intellij.openapi.util.Key;
|
||||||
import com.intellij.openapi.util.UserDataHolder;
|
import com.intellij.util.keyFMap.KeyFMap;
|
||||||
import gnu.trove.THashMap;
|
import gnu.trove.THashMap;
|
||||||
import kotlin.jvm.functions.Function3;
|
import kotlin.jvm.functions.Function3;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -35,7 +35,7 @@ public class SlicedMapImpl implements MutableSlicedMap {
|
|||||||
return new SlicedMapImpl();
|
return new SlicedMapImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<Object, UserDataHolderImpl> map = new THashMap<Object, UserDataHolderImpl>(0);
|
private final Map<Object, KeyFMap> map = new THashMap<Object, KeyFMap>(0);
|
||||||
private Multimap<WritableSlice<?, ?>, Object> collectiveSliceKeys = null;
|
private Multimap<WritableSlice<?, ?>, Object> collectiveSliceKeys = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,17 +44,16 @@ public class SlicedMapImpl implements MutableSlicedMap {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserDataHolderImpl holder = map.get(key);
|
KeyFMap holder = map.get(key);
|
||||||
if (holder == null) {
|
if (holder == null) {
|
||||||
holder = new UserDataHolderImpl();
|
holder = KeyFMap.EMPTY_MAP;
|
||||||
map.put(key, holder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Key<V> sliceKey = slice.getKey();
|
Key<V> sliceKey = slice.getKey();
|
||||||
|
|
||||||
RewritePolicy rewritePolicy = slice.getRewritePolicy();
|
RewritePolicy rewritePolicy = slice.getRewritePolicy();
|
||||||
if (rewritePolicy.rewriteProcessingNeeded(key)) {
|
if (rewritePolicy.rewriteProcessingNeeded(key)) {
|
||||||
V oldValue = holder.getUserData(sliceKey);
|
V oldValue = holder.get(sliceKey);
|
||||||
if (oldValue != null) {
|
if (oldValue != null) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
if (!rewritePolicy.processRewrite(slice, key, oldValue, value)) {
|
if (!rewritePolicy.processRewrite(slice, key, oldValue, value)) {
|
||||||
@@ -71,7 +70,7 @@ public class SlicedMapImpl implements MutableSlicedMap {
|
|||||||
collectiveSliceKeys.put(slice, key);
|
collectiveSliceKeys.put(slice, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.putUserData(sliceKey, value);
|
map.put(key, holder.plus(sliceKey, value));
|
||||||
slice.afterPut(this, key, value);
|
slice.afterPut(this, key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,9 +82,9 @@ public class SlicedMapImpl implements MutableSlicedMap {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
public <K, V> V get(ReadOnlySlice<K, V> 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);
|
return slice.computeValue(this, key, value, value == null);
|
||||||
}
|
}
|
||||||
@@ -101,14 +100,14 @@ public class SlicedMapImpl implements MutableSlicedMap {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(@NotNull Function3<WritableSlice, Object, Object, Void> f) {
|
public void forEach(@NotNull Function3<WritableSlice, Object, Object, Void> f) {
|
||||||
for (Map.Entry<Object, UserDataHolderImpl> entry : map.entrySet()) {
|
for (Map.Entry<Object, KeyFMap> entry : map.entrySet()) {
|
||||||
Object key = entry.getKey();
|
Object key = entry.getKey();
|
||||||
UserDataHolderImpl holder = entry.getValue();
|
KeyFMap holder = entry.getValue();
|
||||||
|
|
||||||
if (holder == null) continue;
|
if (holder == null) continue;
|
||||||
|
|
||||||
for (Key<?> sliceKey : holder.getKeys()) {
|
for (Key<?> sliceKey : holder.getKeys()) {
|
||||||
Object value = holder.getUserData(sliceKey);
|
Object value = holder.get(sliceKey);
|
||||||
|
|
||||||
f.invoke(((AbstractWritableSlice) sliceKey).getSlice(), key, value);
|
f.invoke(((AbstractWritableSlice) sliceKey).getSlice(), key, value);
|
||||||
}
|
}
|
||||||
@@ -120,11 +119,11 @@ public class SlicedMapImpl implements MutableSlicedMap {
|
|||||||
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
|
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
|
||||||
ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
|
ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
|
||||||
|
|
||||||
for (Map.Entry<Object, UserDataHolderImpl> entry : map.entrySet()) {
|
for (Map.Entry<Object, KeyFMap> 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) {
|
if (value != null) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
|
|||||||
Reference in New Issue
Block a user