mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use KeyFMap#getKeys in ExportableUserDataHolderBase to simplify and improve performance
This commit is contained in:
+12
-22
@@ -17,37 +17,27 @@ package com.intellij.openapi.compiler;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.util.keyFMap.KeyFMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExportableUserDataHolderBase extends UserDataHolderBase implements ExportableUserDataHolder{
|
||||
private final Set<Key> myKeys = Collections.synchronizedSet(new HashSet<Key>());
|
||||
|
||||
@NotNull
|
||||
public final Map<Key, Object> exportUserData() {
|
||||
final Map<Key, Object> result = new HashMap<Key, Object>();
|
||||
synchronized (myKeys) {
|
||||
for (Key<?> k : myKeys) {
|
||||
final Object data = getUserData(k);
|
||||
if (data != null) {
|
||||
result.put(k, data);
|
||||
}
|
||||
|
||||
KeyFMap map = getUserMap();
|
||||
Key[] keys = map.getKeys();
|
||||
|
||||
for (Key<?> k : keys) {
|
||||
final Object data = map.get(k);
|
||||
if (data != null) {
|
||||
result.put(k, data);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> void putUserData(@NotNull Key<T> key, @Nullable T value) {
|
||||
if (value != null) {
|
||||
myKeys.add(key);
|
||||
}
|
||||
else {
|
||||
myKeys.remove(key);
|
||||
}
|
||||
super.putUserData(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user