You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/05/30 11:16:30 UTC

[groovy] branch master updated: Trivial refactoring: extract common variables

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 d7f9edc  Trivial refactoring: extract common variables
d7f9edc is described below

commit d7f9edc7209a87d5525b4d44a93eebedc5f11c8c
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun May 30 19:15:52 2021 +0800

    Trivial refactoring: extract common variables
---
 src/main/java/groovy/lang/MetaClassImpl.java | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 8e09444..639514c 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -621,6 +621,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
     }
 
     private void inheritInterfaceNewMetaMethods(final Set<CachedClass> interfaces) {
+        Method[] theClassMethods = null;
         // add methods declared by DGM for interfaces
         for (CachedClass face : interfaces) {
             for (MetaMethod method : getNewMetaMethods(face)) {
@@ -628,11 +629,13 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
                 // skip DGM methods on an interface if the class already has the method
                 // but don't skip for GroovyObject-related methods as it breaks things :-(
                 if (method instanceof GeneratedMetaMethod && !isAssignableFrom(GroovyObject.class, method.getDeclaringClass().getTheClass())) {
-                    for (Method m : theClass.getMethods()) {
-                        if (method.getName().equals(m.getName())
+                    final String generatedMethodName = method.getName();
+                    final CachedClass[] generatedMethodParameterTypes = method.getParameterTypes();
+                    for (Method m : (null == theClassMethods ? theClassMethods = theClass.getMethods() : theClassMethods)) {
+                        if (generatedMethodName.equals(m.getName())
                                 // below not true for DGM#push and also co-variant return scenarios
                                 //&& method.getReturnType().equals(m.getReturnType())
-                                && MetaMethod.equal(method.getParameterTypes(), m.getParameterTypes())) {
+                                && MetaMethod.equal(generatedMethodParameterTypes, m.getParameterTypes())) {
                             skip = true;
                             break;
                         }