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:27:33 UTC

[groovy] branch master updated: Trivial tweak: reduce method calls of `removeAll`

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 78091c3  Trivial tweak: reduce method calls of `removeAll`
78091c3 is described below

commit 78091c3058b79ba6e674201b31cd9fb1e056f4ac
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Jul 12 14:14:29 2020 +0800

    Trivial tweak: reduce method calls of `removeAll`
---
 src/main/java/org/codehaus/groovy/ast/ClassNode.java | 13 ++++++++-----
 1 file changed, 8 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..0f7e362 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
@@ -1102,11 +1102,14 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
 
         // 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);
+        final List<MethodNode> newMethodList = getMethods();
+        if (newMethodList.size() > methodList.size()) { // if the newly added method nodes found, visit them
+            List<MethodNode> changedMethodList = new ArrayList<>(newMethodList);
+            boolean changed = changedMethodList.removeAll(methodList);
+            if (changed) {
+                for (MethodNode mn : changedMethodList) {
+                    visitor.visitMethod(mn);
+                }
             }
         }
     }