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/06/26 11:34:52 UTC

[groovy] branch GROOVY_3_0_X updated (3bad9d4 -> 51a2470)

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

sunlan pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 3bad9d4  Trivial refactoring: remove duplicated code
     new 0bf7747  Improve the performance of `getPropertyName`
     new 3a554f4  Improve the performance of `getPropertyName` further
     new 2a10172  Change type `LinkedList` to `ArrayList` to accelerate iterating
     new 51a2470  Eliminate the tail recursion for better performance

The 4 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:
 .../apache/groovy/ast/tools/MethodNodeUtils.java   | 22 +++++++++++++++-------
 .../java/org/codehaus/groovy/ast/ClassNode.java    |  8 ++++----
 .../groovy/classgen/VariableScopeVisitor.java      | 20 ++++++++++++++++----
 3 files changed, 35 insertions(+), 15 deletions(-)


[groovy] 02/04: Improve the performance of `getPropertyName` further

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

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 3a554f4ea38862b9813120fd47576991b32b8c1e
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jun 26 18:03:09 2020 +0800

    Improve the performance of `getPropertyName` further
    
    (cherry picked from commit 041a7e709ae005a3dec06cdeaf7d5f2e36c9f8cc)
---
 .../java/org/apache/groovy/ast/tools/MethodNodeUtils.java   | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java b/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
index b553d71..1e2b9d8 100644
--- a/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
@@ -77,11 +77,15 @@ public class MethodNodeUtils {
      * @return the property name without the get/set/is prefix if a property or null
      */
     public static String getPropertyName(MethodNode mNode) {
+        boolean startsWithGet = false;
+        boolean startsWithSet = false;
+        boolean startsWithIs = false;
         String name = mNode.getName();
-        final boolean startsWithSet = name.startsWith("set");
-        final boolean startsWithGet = name.startsWith("get");
-        final boolean startsWithIs = name.startsWith("is");
-        if (startsWithGet || startsWithSet || startsWithIs) {
+
+        if ((startsWithGet = name.startsWith("get"))
+                || (startsWithSet = name.startsWith("set"))
+                || (startsWithIs = name.startsWith("is"))) {
+
             final String tmpPname = name.substring(startsWithIs ? 2 : 3);
             if (!tmpPname.isEmpty()) {
                 if (startsWithSet) {
@@ -95,6 +99,7 @@ public class MethodNodeUtils {
                 }
             }
         }
+
         return null;
     }
 


[groovy] 03/04: Change type `LinkedList` to `ArrayList` to accelerate iterating

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

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 2a101723a2bebd20283a8884a1a8bdc7e2027215
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jun 26 18:16:01 2020 +0800

    Change type `LinkedList` to `ArrayList` to accelerate iterating
    
    (cherry picked from commit 8c200eca1f48c1cd991b1278aba8b5f9efdc46d5)
---
 src/main/java/org/codehaus/groovy/ast/ClassNode.java              | 8 ++++----
 .../java/org/codehaus/groovy/classgen/VariableScopeVisitor.java   | 7 ++++---
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/ClassNode.java b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
index 4d0e12f..f6bf3e3 100644
--- a/src/main/java/org/codehaus/groovy/ast/ClassNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/ClassNode.java
@@ -142,7 +142,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
     private List<ConstructorNode> constructors;
     private MapOfLists methods;
     private List<MethodNode> methodsList;
-    private LinkedList<FieldNode> fields;
+    private List<FieldNode> fields;
     private List<PropertyNode> properties;
     private Map<String, FieldNode> fieldIndex;
     private ModuleNode module;
@@ -354,7 +354,7 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
             return redirect.getFields();
         lazyClassInit();
         if (fields == null)
-            fields = new LinkedList<>();
+            fields = new ArrayList<>();
         return fields;
     }
 
@@ -516,12 +516,12 @@ public class ClassNode extends AnnotatedNode implements Opcodes {
         node.setDeclaringClass(r);
         node.setOwner(r);
         if (r.fields == null)
-            r.fields = new LinkedList<>();
+            r.fields = new ArrayList<>();
         if (r.fieldIndex == null)
             r.fieldIndex = new LinkedHashMap<>();
 
         if (isFirst) {
-            r.fields.addFirst(node);
+            r.fields.add(0, node);
         } else {
             r.fields.add(node);
         }
diff --git a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
index ef22321..4ff9a18 100644
--- a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
@@ -180,9 +180,10 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
         for (MethodNode mn : cn.getMethods()) {
             if (name.equals(getPropertyName(mn))) {
                 PropertyNode property = new PropertyNode(name, mn.getModifiers(), ClassHelper.OBJECT_TYPE, cn, null, null, null);
-                property.getField().setHasNoRealSourcePosition(true);
-                property.getField().setSynthetic(true);
-                property.getField().setDeclaringClass(cn);
+                final FieldNode field = property.getField();
+                field.setHasNoRealSourcePosition(true);
+                field.setSynthetic(true);
+                field.setDeclaringClass(cn);
                 property.setDeclaringClass(cn);
                 return property;
             }


[groovy] 01/04: Improve the performance of `getPropertyName`

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

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 0bf77471b19876077d8c2fb9627a47f7ff8cf720
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jun 26 17:18:33 2020 +0800

    Improve the performance of `getPropertyName`
    
    (cherry picked from commit 47f74e369d37fd52f0bb8d09f55596bff64f028d)
---
 .../org/apache/groovy/ast/tools/MethodNodeUtils.java    | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java b/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
index aa7cd3d..b553d71 100644
--- a/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/MethodNodeUtils.java
@@ -78,16 +78,19 @@ public class MethodNodeUtils {
      */
     public static String getPropertyName(MethodNode mNode) {
         String name = mNode.getName();
-        if (name.startsWith("set") || name.startsWith("get") || name.startsWith("is")) {
-            String pname = decapitalize(name.substring(name.startsWith("is") ? 2 : 3));
-            if (!pname.isEmpty()) {
-                if (name.startsWith("set")) {
+        final boolean startsWithSet = name.startsWith("set");
+        final boolean startsWithGet = name.startsWith("get");
+        final boolean startsWithIs = name.startsWith("is");
+        if (startsWithGet || startsWithSet || startsWithIs) {
+            final String tmpPname = name.substring(startsWithIs ? 2 : 3);
+            if (!tmpPname.isEmpty()) {
+                if (startsWithSet) {
                     if (mNode.getParameters().length == 1) {
-                        return pname;
+                        return decapitalize(tmpPname);
                     }
                 } else if (mNode.getParameters().length == 0 && !ClassHelper.VOID_TYPE.equals(mNode.getReturnType())) {
-                    if (name.startsWith("get") || ClassHelper.boolean_TYPE.equals(mNode.getReturnType())) {
-                        return pname;
+                    if (startsWithGet || ClassHelper.boolean_TYPE.equals(mNode.getReturnType())) {
+                        return decapitalize(tmpPname);
                     }
                 }
             }


[groovy] 04/04: Eliminate the tail recursion for better performance

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

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 51a2470a243d24c86d2d00e4ceb5b3aa215eeabb
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jun 26 18:42:44 2020 +0800

    Eliminate the tail recursion for better performance
    
    (cherry picked from commit af7f9a3c6d1fd321b82a164d79a255fce2a9c964)
---
 .../org/codehaus/groovy/classgen/VariableScopeVisitor.java  | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
index 4ff9a18..536630a 100644
--- a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
@@ -167,6 +167,17 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
     }
 
     private Variable findClassMember(final ClassNode cn, final String name) {
+        for (ClassNode classNode = cn; null != classNode; classNode = classNode.getSuperClass()) {
+            Variable variable = doFindClassMember(classNode, name);
+            if (null != variable) {
+                return variable;
+            }
+        }
+
+        return null;
+    }
+
+    private Variable doFindClassMember(final ClassNode cn, final String name) {
         if (cn == null) return null;
 
         if (cn.isScript()) {
@@ -198,7 +209,7 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
             if (fn != null) return fn;
         }
 
-        return findClassMember(cn.getSuperClass(), name);
+        return null;
     }
 
     private Variable findVariableDeclaration(final String name) {