diff options
author | Robbert Jan Grootjans <grootjans@gmail.com> | 2011-12-15 13:01:24 +0100 |
---|---|---|
committer | Robbert Jan Grootjans <grootjans@gmail.com> | 2011-12-15 13:04:45 +0100 |
commit | 306a9efef536b431f43dd46a0d48f6f687295f20 (patch) | |
tree | 4ba3fd3dd85e35ba649c4899782e5c3930113833 | |
parent | 6ccec72c7eb2b673cd534ec12bd44bcf28016b46 (diff) | |
download | lombok-306a9efef536b431f43dd46a0d48f6f687295f20.tar.gz lombok-306a9efef536b431f43dd46a0d48f6f687295f20.tar.bz2 lombok-306a9efef536b431f43dd46a0d48f6f687295f20.zip |
Generated nodes are now cached using a fully-weak Map.
Should hopefully fix Netbeans performance issue #242. Compared heap
dump pre and post-fix, seems to work.
-rw-r--r-- | src/core/lombok/javac/handlers/JavacHandlerUtil.java | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index fc9435d8..2bf6c4ec 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -24,6 +24,7 @@ package lombok.javac.handlers; import static lombok.javac.Javac.*; import java.lang.annotation.Annotation; +import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -89,11 +90,12 @@ public class JavacHandlerUtil { } } - private static Map<JCTree, JCTree> generatedNodes = new WeakHashMap<JCTree, JCTree>(); + private static Map<JCTree, WeakReference<JCTree>> generatedNodes = new WeakHashMap<JCTree, WeakReference<JCTree>>(); public static JCTree getGeneratedBy(JCTree node) { synchronized (generatedNodes) { - return generatedNodes.get(node); + WeakReference<JCTree> ref = generatedNodes.get(node); + return ref == null ? null : ref.get(); } } @@ -111,7 +113,7 @@ public class JavacHandlerUtil { public static <T extends JCTree> T setGeneratedBy(T node, JCTree source) { synchronized (generatedNodes) { if (source == null) generatedNodes.remove(node); - else generatedNodes.put(node, source); + else generatedNodes.put(node, new WeakReference<JCTree>(source)); } return node; } |