groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Trivial refactoring: avoid creating zero length array
Date Mon, 02 Apr 2018 15:58:59 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X ca092951a -> e05db4c25


Trivial refactoring: avoid creating zero length array

(cherry picked from commit 08c197a)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e05db4c2
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e05db4c2
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e05db4c2

Branch: refs/heads/GROOVY_2_6_X
Commit: e05db4c25250e6d9649f4ac37a2aaabbce1a13b1
Parents: ca09295
Author: sunlan <sunlan@apache.org>
Authored: Mon Apr 2 21:57:40 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Mon Apr 2 23:58:52 2018 +0800

----------------------------------------------------------------------
 .../java/org/codehaus/groovy/antlr/AntlrParserPlugin.java    | 8 ++++----
 .../codehaus/groovy/ast/decompiled/ClassSignatureParser.java | 2 +-
 .../codehaus/groovy/ast/decompiled/TypeSignatureParser.java  | 2 +-
 .../org/codehaus/groovy/ast/tools/WideningCategories.java    | 4 ++--
 .../java/org/codehaus/groovy/classgen/InnerClassVisitor.java | 2 +-
 .../java/org/codehaus/groovy/control/OptimizerVisitor.java   | 2 +-
 .../org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java   | 2 +-
 .../groovy/transform/MapConstructorASTTransformation.java    | 2 +-
 .../groovy/transform/NamedVariantASTTransformation.java      | 2 +-
 .../groovy/transform/TupleConstructorASTTransformation.java  | 2 +-
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java      | 6 +++---
 .../groovy/transform/stc/TraitTypeCheckingExtension.java     | 2 +-
 .../codehaus/groovy/transform/stc/UnionTypeClassNode.java    | 6 +++---
 .../org/codehaus/groovy/transform/trait/TraitComposer.java   | 4 ++--
 14 files changed, 23 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
index 7f76590..6ddb6b7 100644
--- a/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
+++ b/src/main/java/org/codehaus/groovy/antlr/AntlrParserPlugin.java
@@ -2608,7 +2608,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin,
Groovy
     private static void setTypeArgumentsOnMethodCallExpression(MethodCallExpression expression,
                                                         List<GenericsType> typeArgumentList)
{
         if (typeArgumentList != null && !typeArgumentList.isEmpty()) {
-            expression.setGenericsTypes(typeArgumentList.toArray(new GenericsType[0]));
+            expression.setGenericsTypes(typeArgumentList.toArray(GenericsType.EMPTY_ARRAY));
         }
     }
 
@@ -3022,7 +3022,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin,
Groovy
     private ClassNode addTypeArguments(ClassNode basicType, AST node) {
         List<GenericsType> typeArgumentList = getTypeArgumentsList(node);
         // a 0-length type argument list means we face the diamond operator
-        basicType.setGenericsTypes(typeArgumentList.toArray(new GenericsType[0]));
+        basicType.setGenericsTypes(typeArgumentList.toArray(GenericsType.EMPTY_ARRAY));
         return basicType;
     }
 
@@ -3055,7 +3055,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin,
Groovy
             bounds.add(bound);
         }
         if (bounds.isEmpty()) return null;
-        return (ClassNode[]) bounds.toArray(new ClassNode[0]);
+        return (ClassNode[]) bounds.toArray(ClassNode.EMPTY_ARRAY);
     }
 
     protected GenericsType[] makeGenericsType(AST rootNode) {
@@ -3073,7 +3073,7 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin,
Groovy
             ret.add(gt);
             typeParameter = typeParameter.getNextSibling();
         }
-        return (GenericsType[]) ret.toArray(new GenericsType[0]);
+        return (GenericsType[]) ret.toArray(GenericsType.EMPTY_ARRAY);
     }
 
     protected ClassNode makeType(AST typeNode) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/ast/decompiled/ClassSignatureParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/ClassSignatureParser.java b/src/main/java/org/codehaus/groovy/ast/decompiled/ClassSignatureParser.java
index 1bfaeb7..2c0d28c 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/ClassSignatureParser.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/ClassSignatureParser.java
@@ -79,6 +79,6 @@ class ClassSignatureParser {
         if (typeParameters.length > 0) {
             classNode.setGenericsTypes(typeParameters);
         }
-        classNode.setInterfaces(interfaces.toArray(new ClassNode[0]));
+        classNode.setInterfaces(interfaces.toArray(ClassNode.EMPTY_ARRAY));
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/ast/decompiled/TypeSignatureParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/decompiled/TypeSignatureParser.java b/src/main/java/org/codehaus/groovy/ast/decompiled/TypeSignatureParser.java
index 5f8f03d..7b217fc 100644
--- a/src/main/java/org/codehaus/groovy/ast/decompiled/TypeSignatureParser.java
+++ b/src/main/java/org/codehaus/groovy/ast/decompiled/TypeSignatureParser.java
@@ -117,7 +117,7 @@ abstract class TypeSignatureParser extends SignatureVisitor {
         }
 
         ClassNode bound = base.getPlainNodeReference();
-        bound.setGenericsTypes(arguments.toArray(new GenericsType[0]));
+        bound.setGenericsTypes(arguments.toArray(GenericsType.EMPTY_ARRAY));
         finished(bound);
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
index 712e80b..57a3e15 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
@@ -573,7 +573,7 @@ public class WideningCategories {
                 itcn.remove();
             }
         }
-        ClassNode[] interfaceArray = interfaces.toArray(new ClassNode[0]);
+        ClassNode[] interfaceArray = interfaces.toArray(ClassNode.EMPTY_ARRAY);
         Arrays.sort(interfaceArray, INTERFACE_CLASSNODE_COMPARATOR);
         type = new LowestUpperBoundClassNode(name, superClass, interfaceArray);
         return type;
@@ -632,7 +632,7 @@ public class WideningCategories {
                         Collections.addAll(asArrayList, genericsTypes);
                     }
                 }
-                setGenericsTypes(asArrayList.toArray(new GenericsType[0]));
+                setGenericsTypes(asArrayList.toArray(GenericsType.EMPTY_ARRAY));
             }
             StringBuilder sb = new StringBuilder();
             if (!upper.equals(OBJECT_TYPE)) sb.append(upper.getName());

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java b/src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java
index 56fbc72..c8a64de 100644
--- a/src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java
+++ b/src/main/java/org/codehaus/groovy/classgen/InnerClassVisitor.java
@@ -219,7 +219,7 @@ public class InnerClassVisitor extends InnerClassVisitorHelper implements
Opcode
             pField.setOriginType(ClassHelper.getWrapper(var.getOriginType()));
         }
 
-        innerClass.addConstructor(ACC_SYNTHETIC, parameters.toArray(new Parameter[0]), ClassNode.EMPTY_ARRAY,
block);
+        innerClass.addConstructor(ACC_SYNTHETIC, parameters.toArray(Parameter.EMPTY_ARRAY),
ClassNode.EMPTY_ARRAY, block);
     }
 
     private boolean isStaticThis(InnerClassNode innerClass, VariableScope scope) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/control/OptimizerVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/control/OptimizerVisitor.java b/src/main/java/org/codehaus/groovy/control/OptimizerVisitor.java
index 24a9c31..b7fa503 100644
--- a/src/main/java/org/codehaus/groovy/control/OptimizerVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/OptimizerVisitor.java
@@ -86,7 +86,7 @@ public class OptimizerVisitor extends ClassCodeExpressionTransformer {
                         newInterfaces.add(classNode);
                     }
                 }
-                node.setInterfaces(newInterfaces.toArray(new ClassNode[0]));
+                node.setInterfaces(newInterfaces.toArray(ClassNode.EMPTY_ARRAY));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java b/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
index 5517087..23858f6 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
@@ -215,7 +215,7 @@ public class ProxyGeneratorAdapter extends ClassVisitor implements Opcodes
{
         }
         if (!traits.isEmpty()) {
             String name = superClass.getName() + "$TraitAdapter";
-            ClassNode cn = new ClassNode(name, ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.OBJECT_TYPE,
traits.toArray(new ClassNode[0]), null);
+            ClassNode cn = new ClassNode(name, ACC_PUBLIC | ACC_ABSTRACT, ClassHelper.OBJECT_TYPE,
traits.toArray(ClassNode.EMPTY_ARRAY), null);
             CompilationUnit cu = new CompilationUnit(loader);
             CompilerConfiguration config = new CompilerConfiguration();
             SourceUnit su = new SourceUnit(name + "wrapper", "", config, loader, new ErrorCollector(config));

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/transform/MapConstructorASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/MapConstructorASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/MapConstructorASTTransformation.java
index 9016c16..709cdb4 100644
--- a/src/main/java/org/codehaus/groovy/transform/MapConstructorASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/MapConstructorASTTransformation.java
@@ -131,7 +131,7 @@ public class MapConstructorASTTransformation extends AbstractASTTransformation
i
                 anno.setMember("pre", new ClosureExpression(Parameter.EMPTY_ARRAY, EmptyStatement.INSTANCE));
             }
             if (post != null) {
-                anno.setMember("post", new ClosureExpression(new Parameter[0], EmptyStatement.INSTANCE));
+                anno.setMember("post", new ClosureExpression(Parameter.EMPTY_ARRAY, EmptyStatement.INSTANCE));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
index 905ced8..64e2b32 100644
--- a/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
@@ -152,7 +152,7 @@ public class NamedVariantASTTransformation extends AbstractASTTransformation
{
                                 plusX(new ConstantExpression("Unrecognized namedArgKey: "),
varX(namedArgKey)))
                 ));
 
-        Parameter[] genParamsArray = genParams.toArray(new Parameter[0]);
+        Parameter[] genParamsArray = genParams.toArray(Parameter.EMPTY_ARRAY);
         // TODO account for default params giving multiple signatures
         if (cNode.hasMethod(mNode.getName(), genParamsArray)) {
             addError("Error during " + MY_TYPE_NAME + " processing. Class " + cNode.getNameWithoutPackage()
+

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
index 6d49c5d..d421a47 100644
--- a/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/TupleConstructorASTTransformation.java
@@ -256,7 +256,7 @@ public class TupleConstructorASTTransformation extends AbstractASTTransformation
 
         boolean hasMapCons = AnnotatedNodeUtils.hasAnnotation(cNode, MapConstructorASTTransformation.MY_TYPE);
         int modifiers = getVisibility(anno, cNode, ConstructorNode.class, ACC_PUBLIC);
-        ConstructorNode consNode = new ConstructorNode(modifiers, params.toArray(new Parameter[0]),
ClassNode.EMPTY_ARRAY, body);
+        ConstructorNode consNode = new ConstructorNode(modifiers, params.toArray(Parameter.EMPTY_ARRAY),
ClassNode.EMPTY_ARRAY, body);
         markAsGenerated(cNode, consNode);
         cNode.addConstructor(consNode);
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 77f2e21..900bdc8 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2144,7 +2144,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
                 } else if (arr.size()==1) {
                     result = arr.get(0);
                 } else {
-                    result = new UnionTypeClassNode(arr.toArray(new ClassNode[0]));
+                    result = new UnionTypeClassNode(arr.toArray(ClassNode.EMPTY_ARRAY));
                 }
             }
         }
@@ -3289,7 +3289,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
                         nodes.add(arg);
                     }
                 }
-                return new LowestUpperBoundClassNode(returnType.getName()+"Composed", OBJECT_TYPE,
nodes.toArray(new ClassNode[0]));
+                return new LowestUpperBoundClassNode(returnType.getName()+"Composed", OBJECT_TYPE,
nodes.toArray(ClassNode.EMPTY_ARRAY));
             }
         }
         return returnType;
@@ -4458,7 +4458,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
         Traits.collectSelfTypes(ret, selfTypes);
         if (!selfTypes.isEmpty()) {
             selfTypes.add(ret);
-            ret = new UnionTypeClassNode(selfTypes.toArray(new ClassNode[0]));
+            ret = new UnionTypeClassNode(selfTypes.toArray(ClassNode.EMPTY_ARRAY));
         }
         return ret;
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java
b/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java
index 3138c18..a7c647f 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java
@@ -111,7 +111,7 @@ public class TraitTypeCheckingExtension extends AbstractTypeCheckingExtension
{
         String traitName = decomposed[0];
         String name = decomposed[1];
         LinkedHashSet<ClassNode> traitsAsList = Traits.collectAllInterfacesReverseOrder(receiver,
new LinkedHashSet<ClassNode>());
-        ClassNode[] implementedTraits = traitsAsList.toArray(new ClassNode[0]);
+        ClassNode[] implementedTraits = traitsAsList.toArray(ClassNode.EMPTY_ARRAY);
         ClassNode nextTrait = null;
         for (int i = 0; i < implementedTraits.length - 1; i++) {
             ClassNode implementedTrait = implementedTraits[i];

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/transform/stc/UnionTypeClassNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/UnionTypeClassNode.java b/src/main/java/org/codehaus/groovy/transform/stc/UnionTypeClassNode.java
index ac23d81..1513421 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/UnionTypeClassNode.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/UnionTypeClassNode.java
@@ -293,7 +293,7 @@ class UnionTypeClassNode extends ClassNode {
             ClassNode[] interfaces = delegate.getInterfaces();
             if (interfaces != null) Collections.addAll(nodes, interfaces);
         }
-        return nodes.toArray(new ClassNode[0]);
+        return nodes.toArray(ClassNode.EMPTY_ARRAY);
     }
 
     @Override
@@ -328,7 +328,7 @@ class UnionTypeClassNode extends ClassNode {
             ClassNode[] interfaces = delegate.getUnresolvedInterfaces();
             if (interfaces != null) Collections.addAll(nodes, interfaces);
         }
-        return nodes.toArray(new ClassNode[0]);
+        return nodes.toArray(ClassNode.EMPTY_ARRAY);
     }
 
     @Override
@@ -338,7 +338,7 @@ class UnionTypeClassNode extends ClassNode {
             ClassNode[] interfaces = delegate.getUnresolvedInterfaces(useRedirect);
             if (interfaces != null) Collections.addAll(nodes, interfaces);
         }
-        return nodes.toArray(new ClassNode[0]);
+        return nodes.toArray(ClassNode.EMPTY_ARRAY);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/groovy/blob/e05db4c2/src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java b/src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java
index b3bdca2..34fe248 100644
--- a/src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java
+++ b/src/main/java/org/codehaus/groovy/transform/trait/TraitComposer.java
@@ -405,7 +405,7 @@ public abstract class TraitComposer {
         }
         if (!modified) return oldTypes;
         if (l.isEmpty()) return null;
-        return l.toArray(new GenericsType[0]);
+        return l.toArray(GenericsType.EMPTY_ARRAY);
     }
 
     /**
@@ -431,7 +431,7 @@ public abstract class TraitComposer {
             }
         }
         for (MethodNode superForwarder : superForwarders) {
-            doCreateSuperForwarder(targetNode, superForwarder, traits.toArray(new ClassNode[0]),
genericsSpec);
+            doCreateSuperForwarder(targetNode, superForwarder, traits.toArray(ClassNode.EMPTY_ARRAY),
genericsSpec);
         }
     }
 


Mime
View raw message