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 2018/05/28 11:55:00 UTC

groovy git commit: Refine the usage of `toArray` in `GroovyShell`(closes #732)

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 43b7c04d1 -> fb8d4184d


Refine the usage of `toArray` in `GroovyShell`(closes #732)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: fb8d4184dfb3c20d0db16f595f30320bdfd9ba3e
Parents: 43b7c04
Author: sunlan <su...@apache.org>
Authored: Mon May 28 19:54:12 2018 +0800
Committer: sunlan <su...@apache.org>
Committed: Mon May 28 19:54:53 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/lang/GroovyShell.java | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/fb8d4184/src/main/groovy/groovy/lang/GroovyShell.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/GroovyShell.java b/src/main/groovy/groovy/lang/GroovyShell.java
index 1ac2fc4..f155b30 100644
--- a/src/main/groovy/groovy/lang/GroovyShell.java
+++ b/src/main/groovy/groovy/lang/GroovyShell.java
@@ -51,6 +51,7 @@ import static org.codehaus.groovy.runtime.InvokerHelper.MAIN_METHOD_NAME;
 public class GroovyShell extends GroovyObjectSupport {
 
     public static final String DEFAULT_CODE_BASE = "/groovy/shell";
+    private static final String[] EMPTY_STRING_ARRAY = new String[0];
 
     private final Binding context;
     private int counter;
@@ -156,8 +157,7 @@ public class GroovyShell extends GroovyObjectSupport {
      * @param list       the command line arguments to pass in
      */
     public Object run(File scriptFile, List list) throws CompilationFailedException, IOException {
-        String[] args = new String[list.size()];
-        return run(scriptFile, (String[]) list.toArray(args));
+        return run(scriptFile, (String[]) list.toArray(EMPTY_STRING_ARRAY));
     }
 
     /**
@@ -168,9 +168,7 @@ public class GroovyShell extends GroovyObjectSupport {
      * @param list       the command line arguments to pass in
      */
     public Object run(String scriptText, String fileName, List list) throws CompilationFailedException {
-        String[] args = new String[list.size()];
-        list.toArray(args);
-        return run(scriptText, fileName, args);
+        return run(scriptText, fileName, (String[]) list.toArray(EMPTY_STRING_ARRAY));
     }
 
     /**
@@ -364,7 +362,7 @@ public class GroovyShell extends GroovyObjectSupport {
      * @param args      the command line arguments to pass in
      */
     public Object run(GroovyCodeSource source, List args) throws CompilationFailedException {
-        return run(source, ((String[]) args.toArray(new String[0])));
+        return run(source, ((String[]) args.toArray(EMPTY_STRING_ARRAY)));
     }
 
     /**
@@ -385,7 +383,7 @@ public class GroovyShell extends GroovyObjectSupport {
      * @param args      the command line arguments to pass in
      */
     public Object run(URI source, List args) throws CompilationFailedException, IOException {
-        return run(new GroovyCodeSource(source), ((String[]) args.toArray(new String[0])));
+        return run(new GroovyCodeSource(source), ((String[]) args.toArray(EMPTY_STRING_ARRAY)));
     }
 
     /**
@@ -406,7 +404,7 @@ public class GroovyShell extends GroovyObjectSupport {
      * @param list     the command line arguments to pass in
      */
     public Object run(final Reader in, final String fileName, List list) throws CompilationFailedException {
-        return run(in, fileName, (String[]) list.toArray(new String[0]));
+        return run(in, fileName, (String[]) list.toArray(EMPTY_STRING_ARRAY));
     }
 
     /**