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 2020/07/12 06:03:48 UTC
[groovy] branch danielsun/tweak-visitMethods created (now b7e9788)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch danielsun/tweak-visitMethods
in repository https://gitbox.apache.org/repos/asf/groovy.git.
at b7e9788 Trivial tweak: use meta data to mark visited method node
This branch includes the following new commits:
new b7e9788 Trivial tweak: use meta data to mark visited method node
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: Trivial tweak: use meta data to mark visited method
node
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch danielsun/tweak-visitMethods
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit b7e97888cf8a3d8cfde6e84f6967d589a6de8399
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Jul 12 14:03:23 2020 +0800
Trivial tweak: use meta data to mark visited method node
---
src/main/java/org/codehaus/groovy/ast/ClassNode.java | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/ast/ClassNode.java b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
index 9eaf47c..a50dcf8 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
@@ -110,6 +110,7 @@ import static org.apache.groovy.ast.tools.MethodNodeUtils.getCodeAsBlock;
* @see org.codehaus.groovy.ast.ClassHelper
*/
public class ClassNode extends AnnotatedNode implements Opcodes {
+ private static final String VISITED = "_VISITED";
private static class MapOfLists {
Map<Object, List<MethodNode>> map;
@@ -1098,16 +1099,17 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
List<MethodNode> methodList = new ArrayList<>(getMethods());
for (MethodNode mn : methodList) {
visitor.visitMethod(mn);
+ mn.putNodeMetaData(VISITED, true);
}
// visit the method nodes added while iterating,
// e.g. synthetic method for constructor reference
List<MethodNode> changedMethodList = new ArrayList<>(getMethods());
- boolean changed = changedMethodList.removeAll(methodList);
- if (changed) {
- for (MethodNode mn : changedMethodList) {
- visitor.visitMethod(mn);
- }
+ for (MethodNode mn : changedMethodList) {
+ Boolean visited = mn.getNodeMetaData(VISITED);
+ if (null != visited && visited) continue;
+
+ visitor.visitMethod(mn);
}
}