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 08:51:48 UTC
[groovy] branch danielsun/minor-tweak-object-methods-check-20220807 created (now f55bd7e239)
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
at f55bd7e239 Avoid unnecessary checking for object methods
This branch includes the following new commits:
new f55bd7e239 Avoid unnecessary checking for object methods
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.
[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 f55bd7e239e1bbef1c8b1d69012e5af26860e7d2
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 | 12 +++++++++++-
1 file changed, 11 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..8b0d289a43 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassHelper.java
@@ -64,11 +64,13 @@ import java.lang.ref.SoftReference;
import java.math.BigDecimal;
import java.math.BigInteger;
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 +568,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 +636,7 @@ public class ClassHelper {
return source.getUnresolvedSuperClass();
}
+
+ private static final Set<String> OBJECT_METHOD_NAME_SET =
+ Collections.unmodifiableSet(OBJECT_TYPE.getAllDeclaredMethods().stream().map(m -> m.getName()).collect(Collectors.toSet()));
}