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 2019/11/03 15:19:40 UTC

[groovy] branch master updated (5143bb7 -> ed33b22)

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

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


    from 5143bb7  Trivial refactoring: Comparator combinator can be used
     new 001ffd1  Trivial refactoring: replaced with empty array
     new 56a9452  Trivial refactoring: Can be replaced with `size() != 1`
     new ed33b22  Trivial refactoring: remove unnecessary check and cast

The 3 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/groovy/util/NodeList.java                            | 2 +-
 .../java/org/codehaus/groovy/classgen/VariableScopeVisitor.java    | 7 +++----
 .../java/org/codehaus/groovy/control/CompilerConfiguration.java    | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)


[groovy] 01/03: Trivial refactoring: replaced with empty array

Posted by su...@apache.org.
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

commit 001ffd1392be735642cb58a839bff9a3ee77cb09
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 3 23:04:47 2019 +0800

    Trivial refactoring: replaced with empty array
    
    There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]).
    
    In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call [...]
---
 src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index d75c7ec..a9c825a 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -114,7 +114,7 @@ public class CompilerConfiguration {
     );
 
     /** The valid targetBytecode values. */
-    public static final String[] ALLOWED_JDKS = JDK_TO_BYTECODE_VERSION_MAP.keySet().toArray(new String[JDK_TO_BYTECODE_VERSION_MAP.size()]);
+    public static final String[] ALLOWED_JDKS = JDK_TO_BYTECODE_VERSION_MAP.keySet().toArray(new String[0]);
 
     /**
      * The default source encoding


[groovy] 02/03: Trivial refactoring: Can be replaced with `size() != 1`

Posted by su...@apache.org.
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

commit 56a9452fb99657bc885a28b797b5bcbe3d3669db
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 3 23:06:50 2019 +0800

    Trivial refactoring: Can be replaced with `size() != 1`
---
 src/main/java/groovy/util/NodeList.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/groovy/util/NodeList.java b/src/main/java/groovy/util/NodeList.java
index c4fac31..2aae2fb 100644
--- a/src/main/java/groovy/util/NodeList.java
+++ b/src/main/java/groovy/util/NodeList.java
@@ -185,7 +185,7 @@ public class NodeList extends ArrayList {
     }
 
     public Node replaceNode(Closure c) {
-        if (size() <= 0 || size() > 1) {
+        if (size() != 1) {
             throw new GroovyRuntimeException(
                     "replaceNode() can only be used to replace a single node, but was applied to " + size() + " nodes");
         }


[groovy] 03/03: Trivial refactoring: remove unnecessary check and cast

Posted by su...@apache.org.
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

commit ed33b22fe20134569063bf03989d5516f9a51e34
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 3 23:11:52 2019 +0800

    Trivial refactoring: remove unnecessary check and cast
---
 .../java/org/codehaus/groovy/classgen/VariableScopeVisitor.java    | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
index e6ffc6f..8d4a738 100644
--- a/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/VariableScopeVisitor.java
@@ -518,13 +518,12 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
     public void visitMethodCallExpression(MethodCallExpression call) {
         if (call.isImplicitThis() && call.getMethod() instanceof ConstantExpression) {
             ConstantExpression methodNameConstant = (ConstantExpression) call.getMethod();
-            Object value = methodNameConstant.getText();
+            String methodName = methodNameConstant.getText();
 
-            if (!(value instanceof String)) {
-                throw new GroovyBugError("tried to make a method call with a non-String constant method name.");
+            if (methodName == null) {
+                throw new GroovyBugError("method name is null");
             }
 
-            String methodName = (String) value;
             Variable v = checkVariableNameForDeclaration(methodName, call);
             if (v != null && !(v instanceof DynamicVariable)) {
                 checkVariableContextAccess(v, call);