Got rid of using UserDataHolderBase: using HashMap instead. Thread safety is not neccessary for CompilerConfiguration.

This commit is contained in:
Evgeny Gerashchenko
2012-07-24 17:27:16 +04:00
parent 9a5fc78b85
commit 340a3537ff
@@ -17,39 +17,34 @@
package org.jetbrains.jet.config; package org.jetbrains.jet.config;
import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.UserDataHolderBase;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Collection; import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* @author Evgeny Gerashchenko * @author Evgeny Gerashchenko
* @since 7/3/12 * @since 7/3/12
*/ */
public class CompilerConfiguration { public class CompilerConfiguration {
private final UserDataHolderBase holder = new UserDataHolderBase(); private final Map<Key, Object> map = new HashMap<Key, Object>();
private boolean readOnly = false; private boolean readOnly = false;
@Nullable @Nullable
public <T> T get(@NotNull Key<T> key) { public <T> T get(@NotNull Key<T> key) {
T data = holder.getUserData(key); T data = (T) map.get(key);
return data == null ? null : unmodifiable(data); return data == null ? null : unmodifiable(data);
} }
@NotNull @NotNull
public <T> T get(@NotNull Key<T> key, @NotNull T defaultValue) { public <T> T get(@NotNull Key<T> key, @NotNull T defaultValue) {
T data = holder.getUserData(key); T data = (T) map.get(key);
return data == null ? defaultValue : unmodifiable(data); return data == null ? defaultValue : unmodifiable(data);
} }
@NotNull @NotNull
public <T> List<T> getList(@NotNull Key<List<T>> key) { public <T> List<T> getList(@NotNull Key<List<T>> key) {
List<T> data = holder.getUserData(key); List<T> data = (List<T>) map.get(key);
if (data == null) { if (data == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
@@ -60,24 +55,30 @@ public class CompilerConfiguration {
public <T> void put(@NotNull Key<T> key, @Nullable T value) { public <T> void put(@NotNull Key<T> key, @Nullable T value) {
checkReadOnly(); checkReadOnly();
holder.putUserData(key, value); map.put(key, value);
} }
public <T> void add(@NotNull Key<List<T>> key, @NotNull T value) { public <T> void add(@NotNull Key<List<T>> key, @NotNull T value) {
checkReadOnly(); checkReadOnly();
List<T> list = holder.putUserDataIfAbsent(key, new CopyOnWriteArrayList<T>()); if (map.get(key) == null) {
map.put(key, new ArrayList<T>());
}
List<T> list = (List<T>) map.get(key);
list.add(value); list.add(value);
} }
public <T> void addAll(@NotNull Key<List<T>> key, @NotNull Collection<T> value) { public <T> void addAll(@NotNull Key<List<T>> key, @NotNull Collection<T> values) {
checkReadOnly(); checkReadOnly();
List<T> list = holder.putUserDataIfAbsent(key, new CopyOnWriteArrayList<T>()); if (map.get(key) == null) {
list.addAll(value); map.put(key, new ArrayList<T>());
}
List<T> list = (List<T>) map.get(key);
list.addAll(values);
} }
public CompilerConfiguration copy() { public CompilerConfiguration copy() {
CompilerConfiguration copy = new CompilerConfiguration(); CompilerConfiguration copy = new CompilerConfiguration();
holder.copyUserDataTo(copy.holder); copy.map.putAll(map);
return copy; return copy;
} }