blackdrag commented on code in PR #2018:
URL: https://github.com/apache/groovy/pull/2018#discussion_r1434409694


##########
src/main/java/org/codehaus/groovy/reflection/CachedClass.java:
##########
@@ -282,14 +274,36 @@ public CachedMethod searchMethods(String name, 
CachedClass[] parameterTypes) {
         CachedMethod res = null;
         for (CachedMethod m : methods) {
             if (m.getName().equals(name)
-                    && ReflectionCache.arrayContentsEq(parameterTypes, 
m.getParameterTypes())
+                    && arrayContentsEq(parameterTypes, m.getParameterTypes())
                     && (res == null || 
res.getReturnType().isAssignableFrom(m.getReturnType())))
                 res = m;
         }
 
         return res;
     }
 
+    private static boolean arrayContentsEq(Object[] a1, Object[] a2) {
+        if (a1 == null) {
+            return a2 == null || a2.length == 0;
+        }
+
+        if (a2 == null) {
+            return a1.length == 0;
+        }
+
+        if (a1.length != a2.length) {
+            return false;
+        }
+
+        for (int i = 0; i < a1.length; i++) {
+            if (a1[i] != a2[i]) {
+                return false;
+            }
+        }
+
+        return true;
+    }

Review Comment:
   > Is there a DGM or JVM method for this now?
   
   for line 298+ maybe, though I did not see a DGM for this. There is of course 
DefaultTypeTransformation#compareArrayEqual, but I would not want to use 
Array.get if I don't have to. Arrays.equals(a1,a2) could be used for line 
294+... It does call equals instead of doing a reference check, but since the 
Objects in question here are Class instances and Class#equals does also only a 
reference check it is possible.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@groovy.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to