groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject groovy git commit: ConversionHandler minor improvements (closes #237)
Date Tue, 12 Jan 2016 01:12:01 GMT
Repository: groovy
Updated Branches:
  refs/heads/master f2a2fc059 -> 606891d85


ConversionHandler minor improvements (closes #237)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/606891d8
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/606891d8
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/606891d8

Branch: refs/heads/master
Commit: 606891d85bedbda8139882f41eef531f5752d99f
Parents: f2a2fc0
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Sun Jan 10 10:20:49 2016 -0800
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Mon Jan 11 17:08:31 2016 -0800

----------------------------------------------------------------------
 .../groovy/runtime/ConversionHandler.java         | 18 ++++++++++++------
 .../codehaus/groovy/runtime/ConvertedClosure.java |  5 +++--
 .../org/codehaus/groovy/runtime/ConvertedMap.java |  3 +++
 3 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/606891d8/src/main/org/codehaus/groovy/runtime/ConversionHandler.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/ConversionHandler.java b/src/main/org/codehaus/groovy/runtime/ConversionHandler.java
index 929642d..8bf7c69 100644
--- a/src/main/org/codehaus/groovy/runtime/ConversionHandler.java
+++ b/src/main/org/codehaus/groovy/runtime/ConversionHandler.java
@@ -42,11 +42,15 @@ import java.util.concurrent.ConcurrentHashMap;
  * @author <a href="mailto:blackdrag@gmx.org">Jochen Theodorou</a>
  */
 public abstract class ConversionHandler implements InvocationHandler, Serializable {
-    private Object delegate;
+    private final Object delegate;
     private static final long serialVersionUID = 1162833717190835227L;
-    private ConcurrentHashMap handleCache;
+    private final ConcurrentHashMap<Method, Object> handleCache;
     {
-        if (VMPluginFactory.getPlugin().getVersion()>=7) handleCache = new ConcurrentHashMap();
+        if (VMPluginFactory.getPlugin().getVersion() >= 7) {
+            handleCache = new ConcurrentHashMap<Method, Object>(16, 0.9f, 2);
+        } else {
+            handleCache = null;
+        }
     }
 
     private MetaClass metaClass;
@@ -58,7 +62,9 @@ public abstract class ConversionHandler implements InvocationHandler, Serializab
      * @throws IllegalArgumentException if the given delegate is null
      */
     public ConversionHandler(Object delegate) {
-        if (delegate == null) throw new IllegalArgumentException("delegate must not be null");
+        if (delegate == null) {
+            throw new IllegalArgumentException("delegate must not be null");
+        }
         this.delegate = delegate;
     }
 
@@ -96,8 +102,8 @@ public abstract class ConversionHandler implements InvocationHandler, Serializab
      * @see InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
      */
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-        VMPlugin plugin = VMPluginFactory.getPlugin();
-        if (plugin.getVersion()>=7 && isDefaultMethod(method)) {
+        if (handleCache != null && isDefaultMethod(method)) {
+            VMPlugin plugin = VMPluginFactory.getPlugin();
             Object handle = handleCache.get(method);
             if (handle == null) {
                 handle = plugin.getInvokeSpecialHandle(method, proxy);

http://git-wip-us.apache.org/repos/asf/groovy/blob/606891d8/src/main/org/codehaus/groovy/runtime/ConvertedClosure.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/ConvertedClosure.java b/src/main/org/codehaus/groovy/runtime/ConvertedClosure.java
index 56211aa..dfc7ea0 100644
--- a/src/main/org/codehaus/groovy/runtime/ConvertedClosure.java
+++ b/src/main/org/codehaus/groovy/runtime/ConvertedClosure.java
@@ -31,7 +31,7 @@ import java.lang.reflect.Method;
  * Jul 27, 2006 3:50:51 PM
  */
 public class ConvertedClosure extends ConversionHandler implements Serializable {
-    private String methodName;
+    private final String methodName;
     private static final long serialVersionUID = 1162833713450835227L;
 
     /**
@@ -46,7 +46,8 @@ public class ConvertedClosure extends ConversionHandler implements Serializable
     public ConvertedClosure(Closure closure) {
         this(closure,null);
     }
-    
+
+    @Override
     public Object invokeCustom(Object proxy, Method method, Object[] args)
     throws Throwable {
         if (methodName!=null && !methodName.equals(method.getName())) return null;

http://git-wip-us.apache.org/repos/asf/groovy/blob/606891d8/src/main/org/codehaus/groovy/runtime/ConvertedMap.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/ConvertedMap.java b/src/main/org/codehaus/groovy/runtime/ConvertedMap.java
index 81a76a7..811f269 100644
--- a/src/main/org/codehaus/groovy/runtime/ConvertedMap.java
+++ b/src/main/org/codehaus/groovy/runtime/ConvertedMap.java
@@ -40,6 +40,7 @@ public class ConvertedMap extends ConversionHandler {
         super(closures);
     }
 
+    @Override
     public Object invokeCustom(Object proxy, Method method, Object[] args)
             throws Throwable {
         Map m = (Map) getDelegate();
@@ -53,10 +54,12 @@ public class ConvertedMap extends ConversionHandler {
         return cl.call(args);
     }
 
+    @Override
     public String toString() {
         return DefaultGroovyMethods.toString(getDelegate());
     }
 
+    @Override
     protected boolean checkMethod(Method method) {
         return isCoreObjectMethod(method);
     }


Mime
View raw message