groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 15/18: Trivial refactoring: replaced with empty array
Date Sun, 03 Nov 2019 15:42:31 GMT
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 be4e98fcbb2535edf666f329585a96ae47614c7f
Author: Daniel Sun <sunlan@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 [...]
    
    (cherry picked from commit 001ffd1392be735642cb58a839bff9a3ee77cb09)
---
 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 f30b3b6..3ed8da0 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


Mime
View raw message