groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] branch master updated: Minor refactoring: Avoid redundant method invocation
Date Sun, 11 Aug 2019 19:55:49 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 0a67384  Minor refactoring: Avoid redundant method invocation
0a67384 is described below

commit 0a673844f0ba8377baff7f1db7d6993ba10adf23
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Mon Aug 12 03:46:39 2019 +0800

    Minor refactoring: Avoid redundant method invocation
---
 src/main/java/groovy/lang/MetaClassImpl.java       | 11 ++++----
 .../groovy/runtime/callsite/CallSiteHelper.java    | 33 ----------------------
 .../runtime/callsite/PogoMetaMethodSite.java       | 15 ++++++----
 .../runtime/callsite/PojoMetaMethodSite.java       | 15 ++++++----
 4 files changed, 24 insertions(+), 50 deletions(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 82fb16d..ee4f01e 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -48,7 +48,6 @@ import org.codehaus.groovy.runtime.MetaClassHelper;
 import org.codehaus.groovy.runtime.MethodClosure;
 import org.codehaus.groovy.runtime.callsite.AbstractCallSite;
 import org.codehaus.groovy.runtime.callsite.CallSite;
-import org.codehaus.groovy.runtime.callsite.CallSiteHelper;
 import org.codehaus.groovy.runtime.callsite.ConstructorSite;
 import org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite;
 import org.codehaus.groovy.runtime.callsite.PogoMetaClassSite;
@@ -78,6 +77,8 @@ import org.codehaus.groovy.runtime.wrappers.Wrapper;
 import org.codehaus.groovy.util.ComplexKeyHashMap;
 import org.codehaus.groovy.util.FastArray;
 import org.codehaus.groovy.util.SingleKeyHashMap;
+import org.codehaus.groovy.vmplugin.VMPlugin;
+import org.codehaus.groovy.vmplugin.VMPluginFactory;
 import org.objectweb.asm.ClassVisitor;
 
 import java.beans.BeanInfo;
@@ -119,7 +120,7 @@ import static org.codehaus.groovy.reflection.ReflectionCache.isAssignableFrom;
  * @see groovy.lang.MetaClass
  */
 public class MetaClassImpl implements MetaClass, MutableMetaClass {
-
+    private static final VMPlugin VM_PLUGIN = VMPluginFactory.getPlugin();
     public static final Object[] EMPTY_ARGUMENTS = {};
 
     protected static final String STATIC_METHOD_MISSING = "$static_methodMissing";
@@ -1279,7 +1280,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
         }
 
         if (method != null) {
-            MetaMethod transformedMetaMethod = CallSiteHelper.transformMetaMethod(this, method,
MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+            MetaMethod transformedMetaMethod = VM_PLUGIN.transformMetaMethod(this, method,
MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
             return transformedMetaMethod.doMethodInvoke(object, arguments);
         } else {
             return invokePropertyOrMissing(object, methodName, originalArguments, fromInsideClass,
isCallToSuper);
@@ -1922,7 +1923,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
             //----------------------------------------------------------------------
             // executing the getter method
             //----------------------------------------------------------------------
-            MetaMethod transformedMetaMethod = CallSiteHelper.transformMetaMethod(this, method,
MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+            MetaMethod transformedMetaMethod = VM_PLUGIN.transformMetaMethod(this, method,
MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
             return transformedMetaMethod.doMethodInvoke(object, arguments);
         }
 
@@ -2842,7 +2843,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
                 arguments[1] = newValue;
             }
 
-            MetaMethod transformedMetaMethod = CallSiteHelper.transformMetaMethod(this, method,
MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+            MetaMethod transformedMetaMethod = VM_PLUGIN.transformMetaMethod(this, method,
MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
             transformedMetaMethod.doMethodInvoke(object, arguments);
             return;
         }
diff --git a/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java b/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java
deleted file mode 100644
index 016c537..0000000
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package org.codehaus.groovy.runtime.callsite;
-
-import groovy.lang.MetaClass;
-import groovy.lang.MetaMethod;
-import org.codehaus.groovy.vmplugin.VMPlugin;
-import org.codehaus.groovy.vmplugin.VMPluginFactory;
-
-public class CallSiteHelper {
-    private static final VMPlugin VM_PLUGIN = VMPluginFactory.getPlugin();
-
-    public static MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod,
Class<?>[] params, Class<?> caller) {
-        return VM_PLUGIN.transformMetaMethod(metaClass, metaMethod, params, caller);
-    }
-
-}
diff --git a/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite.java b/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite.java
index 49a2da0..cc8be1e 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaMethodSite.java
@@ -26,6 +26,8 @@ import org.codehaus.groovy.reflection.CachedMethod;
 import org.codehaus.groovy.runtime.GroovyCategorySupport;
 import org.codehaus.groovy.runtime.MetaClassHelper;
 import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
+import org.codehaus.groovy.vmplugin.VMPlugin;
+import org.codehaus.groovy.vmplugin.VMPluginFactory;
 
 import java.lang.reflect.Method;
 
@@ -35,9 +37,10 @@ import java.lang.reflect.Method;
  *   method - cached
 */
 public class PogoMetaMethodSite extends PlainObjectMetaMethodSite {
+    private static final VMPlugin VM_PLUGIN = VMPluginFactory.getPlugin();
     private final int version;
     private final boolean skipVersionCheck;
-    public PogoMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod,
Class params[]) {
+    public PogoMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod,
Class[] params) {
         super(site, metaClass, metaMethod, params);
         version = metaClass.getVersion();
         skipVersionCheck = metaClass.getClass()==MetaClassImpl.class;
@@ -157,7 +160,7 @@ public class PogoMetaMethodSite extends PlainObjectMetaMethodSite {
         final Method reflect;
 
         public PogoCachedMethodSite(CallSite site, MetaClassImpl metaClass, CachedMethod
metaMethod, Class[] params) {
-            super(site, metaClass, CallSiteHelper.transformMetaMethod(metaClass, metaMethod,
params, site.getArray().owner), params);
+            super(site, metaClass, VM_PLUGIN.transformMetaMethod(metaClass, metaMethod, params,
site.getArray().owner), params);
             reflect = ((CachedMethod) super.metaMethod).setAccessible();
         }
 
@@ -170,7 +173,7 @@ public class PogoMetaMethodSite extends PlainObjectMetaMethodSite {
 
     public static class PogoCachedMethodSiteNoUnwrap extends PogoCachedMethodSite {
 
-        public PogoCachedMethodSiteNoUnwrap(CallSite site, MetaClassImpl metaClass, CachedMethod
metaMethod, Class params[]) {
+        public PogoCachedMethodSiteNoUnwrap(CallSite site, MetaClassImpl metaClass, CachedMethod
metaMethod, Class[] params) {
             super(site, metaClass, metaMethod, params);
         }
 
@@ -182,7 +185,7 @@ public class PogoMetaMethodSite extends PlainObjectMetaMethodSite {
 
     public static class PogoCachedMethodSiteNoUnwrapNoCoerce extends PogoCachedMethodSite
{
 
-        public PogoCachedMethodSiteNoUnwrapNoCoerce(CallSite site, MetaClassImpl metaClass,
CachedMethod metaMethod, Class params[]) {
+        public PogoCachedMethodSiteNoUnwrapNoCoerce(CallSite site, MetaClassImpl metaClass,
CachedMethod metaMethod, Class[] params) {
             super(site, metaClass, metaMethod, params);
         }
 
@@ -196,7 +199,7 @@ public class PogoMetaMethodSite extends PlainObjectMetaMethodSite {
      */
     public static class PogoMetaMethodSiteNoUnwrap extends PogoMetaMethodSite {
 
-        public PogoMetaMethodSiteNoUnwrap(CallSite site, MetaClassImpl metaClass, MetaMethod
metaMethod, Class params[]) {
+        public PogoMetaMethodSiteNoUnwrap(CallSite site, MetaClassImpl metaClass, MetaMethod
metaMethod, Class[] params) {
             super(site, metaClass, metaMethod, params);
         }
 
@@ -214,7 +217,7 @@ public class PogoMetaMethodSite extends PlainObjectMetaMethodSite {
      */
     public static class PogoMetaMethodSiteNoUnwrapNoCoerce extends PogoMetaMethodSite {
 
-        public PogoMetaMethodSiteNoUnwrapNoCoerce(CallSite site, MetaClassImpl metaClass,
MetaMethod metaMethod, Class params[]) {
+        public PogoMetaMethodSiteNoUnwrapNoCoerce(CallSite site, MetaClassImpl metaClass,
MetaMethod metaMethod, Class[] params) {
             super(site, metaClass, metaMethod, params);
         }
 
diff --git a/src/main/java/org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite.java b/src/main/java/org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite.java
index 2e22c47..e1ab089 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/PojoMetaMethodSite.java
@@ -26,6 +26,8 @@ import org.codehaus.groovy.runtime.GroovyCategorySupport;
 import org.codehaus.groovy.runtime.MetaClassHelper;
 import org.codehaus.groovy.runtime.NullObject;
 import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
+import org.codehaus.groovy.vmplugin.VMPlugin;
+import org.codehaus.groovy.vmplugin.VMPluginFactory;
 
 import java.lang.reflect.Method;
 
@@ -35,10 +37,11 @@ import java.lang.reflect.Method;
  *   method - cached
 */
 public class PojoMetaMethodSite extends PlainObjectMetaMethodSite {
+    private static final VMPlugin VM_PLUGIN = VMPluginFactory.getPlugin();
 
     protected final int version;
 
-    public PojoMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod,
Class params[]) {
+    public PojoMetaMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod,
Class[] params) {
         super(site, metaClass, metaMethod, params);
         version = metaClass.getVersion();
     }
@@ -178,7 +181,7 @@ public class PojoMetaMethodSite extends PlainObjectMetaMethodSite {
         final Method reflect;
 
         public PojoCachedMethodSite(CallSite site, MetaClassImpl metaClass, MetaMethod metaMethod,
Class[] params) {
-            super(site, metaClass, CallSiteHelper.transformMetaMethod(metaClass, metaMethod,
params, site.getArray().owner), params);
+            super(site, metaClass, VM_PLUGIN.transformMetaMethod(metaClass, metaMethod, params,
site.getArray().owner), params);
             reflect = ((CachedMethod) super.metaMethod).setAccessible();
         }
 
@@ -191,7 +194,7 @@ public class PojoMetaMethodSite extends PlainObjectMetaMethodSite {
 
     public static class PojoCachedMethodSiteNoUnwrap extends PojoCachedMethodSite {
 
-        public PojoCachedMethodSiteNoUnwrap(CallSite site, MetaClassImpl metaClass, MetaMethod
metaMethod, Class params[]) {
+        public PojoCachedMethodSiteNoUnwrap(CallSite site, MetaClassImpl metaClass, MetaMethod
metaMethod, Class[] params) {
             super(site, metaClass, metaMethod, params);
         }
 
@@ -203,7 +206,7 @@ public class PojoMetaMethodSite extends PlainObjectMetaMethodSite {
 
     public static class PojoCachedMethodSiteNoUnwrapNoCoerce extends PojoCachedMethodSite
{
 
-        public PojoCachedMethodSiteNoUnwrapNoCoerce(CallSite site, MetaClassImpl metaClass,
MetaMethod metaMethod, Class params[]) {
+        public PojoCachedMethodSiteNoUnwrapNoCoerce(CallSite site, MetaClassImpl metaClass,
MetaMethod metaMethod, Class[] params) {
             super(site, metaClass, metaMethod, params);
         }
 
@@ -217,7 +220,7 @@ public class PojoMetaMethodSite extends PlainObjectMetaMethodSite {
      */
     public static class PojoMetaMethodSiteNoUnwrap extends PojoMetaMethodSite {
 
-        public PojoMetaMethodSiteNoUnwrap(CallSite site, MetaClassImpl metaClass, MetaMethod
metaMethod, Class params[]) {
+        public PojoMetaMethodSiteNoUnwrap(CallSite site, MetaClassImpl metaClass, MetaMethod
metaMethod, Class[] params) {
             super(site, metaClass, metaMethod, params);
         }
 
@@ -235,7 +238,7 @@ public class PojoMetaMethodSite extends PlainObjectMetaMethodSite {
      */
     public static class PojoMetaMethodSiteNoUnwrapNoCoerce extends PojoMetaMethodSite {
 
-        public PojoMetaMethodSiteNoUnwrapNoCoerce(CallSite site, MetaClassImpl metaClass,
MetaMethod metaMethod, Class params[]) {
+        public PojoMetaMethodSiteNoUnwrapNoCoerce(CallSite site, MetaClassImpl metaClass,
MetaMethod metaMethod, Class[] params) {
             super(site, metaClass, metaMethod, params);
         }
 


Mime
View raw message