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 2022/08/07 09:25:18 UTC

[groovy] branch danielsun/minor-tweak-object-methods-check-20220807 updated (dde6052720 -> 4e98544041)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch danielsun/minor-tweak-object-methods-check-20220807
in repository https://gitbox.apache.org/repos/asf/groovy.git


 discard dde6052720 Avoid unnecessary checking for object methods
     new 4e98544041 Avoid unnecessary checking for object methods

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (dde6052720)
            \
             N -- N -- N   refs/heads/danielsun/minor-tweak-object-methods-check-20220807 (4e98544041)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/main/java/org/codehaus/groovy/ast/ClassHelper.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


[groovy] 01/01: Avoid unnecessary checking for object methods

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/minor-tweak-object-methods-check-20220807
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 4e98544041f95ffe35ca0e1e2292a85a1ef07a9a
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Aug 7 16:49:08 2022 +0800

    Avoid unnecessary checking for object methods
---
 src/main/java/org/codehaus/groovy/ast/ClassHelper.java | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
index d4daf9face..bb8eb18d52 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
@@ -63,12 +63,15 @@ import java.lang.invoke.SerializedLambda;
 import java.lang.ref.SoftReference;
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf;
@@ -566,7 +569,12 @@ public class ClassHelper {
             for (MethodNode mn : type.getAbstractMethods()) {
                 // ignore methods that will have an implementation
                 if (Traits.hasDefaultImplementation(mn)) continue;
-                if (OBJECT_TYPE.getDeclaredMethod(mn.getName(), mn.getParameters()) != null) continue;
+
+                final String name = mn.getName();
+                if (OBJECT_METHOD_NAME_SET.contains(name)) {
+                    // Avoid unnecessary checking for object methods as possible as we could
+                    if (OBJECT_TYPE.getDeclaredMethod(name, mn.getParameters()) != null) continue;
+                }
 
                 // we have two methods, so no SAM
                 if (sam != null) return null;
@@ -629,4 +637,7 @@ public class ClassHelper {
 
         return source.getUnresolvedSuperClass();
     }
+
+    private static final Set<String> OBJECT_METHOD_NAME_SET =
+            Collections.unmodifiableSet(Arrays.stream(Object.class.getMethods()).map(m -> m.getName()).collect(Collectors.toSet()));
 }