From 340a3537ff09e59ee2a8e3f11fbd23ee06f89fb9 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 24 Jul 2012 17:27:16 +0400 Subject: [PATCH] Got rid of using UserDataHolderBase: using HashMap instead. Thread safety is not neccessary for CompilerConfiguration. --- .../jet/config/CompilerConfiguration.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/config/CompilerConfiguration.java b/compiler/frontend/src/org/jetbrains/jet/config/CompilerConfiguration.java index 50b72b2a688..6684ca8e29c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/config/CompilerConfiguration.java +++ b/compiler/frontend/src/org/jetbrains/jet/config/CompilerConfiguration.java @@ -17,39 +17,34 @@ package org.jetbrains.jet.config; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.UserDataHolderBase; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; +import java.util.*; /** * @author Evgeny Gerashchenko * @since 7/3/12 */ public class CompilerConfiguration { - private final UserDataHolderBase holder = new UserDataHolderBase(); + private final Map map = new HashMap(); private boolean readOnly = false; @Nullable public T get(@NotNull Key key) { - T data = holder.getUserData(key); + T data = (T) map.get(key); return data == null ? null : unmodifiable(data); } @NotNull public T get(@NotNull Key key, @NotNull T defaultValue) { - T data = holder.getUserData(key); + T data = (T) map.get(key); return data == null ? defaultValue : unmodifiable(data); } @NotNull public List getList(@NotNull Key> key) { - List data = holder.getUserData(key); + List data = (List) map.get(key); if (data == null) { return Collections.emptyList(); } @@ -60,24 +55,30 @@ public class CompilerConfiguration { public void put(@NotNull Key key, @Nullable T value) { checkReadOnly(); - holder.putUserData(key, value); + map.put(key, value); } public void add(@NotNull Key> key, @NotNull T value) { checkReadOnly(); - List list = holder.putUserDataIfAbsent(key, new CopyOnWriteArrayList()); + if (map.get(key) == null) { + map.put(key, new ArrayList()); + } + List list = (List) map.get(key); list.add(value); } - public void addAll(@NotNull Key> key, @NotNull Collection value) { + public void addAll(@NotNull Key> key, @NotNull Collection values) { checkReadOnly(); - List list = holder.putUserDataIfAbsent(key, new CopyOnWriteArrayList()); - list.addAll(value); + if (map.get(key) == null) { + map.put(key, new ArrayList()); + } + List list = (List) map.get(key); + list.addAll(values); } public CompilerConfiguration copy() { CompilerConfiguration copy = new CompilerConfiguration(); - holder.copyUserDataTo(copy.holder); + copy.map.putAll(map); return copy; }