]> source.dussan.org Git - aspectj.git/commit
Collection.toArray() call style
authorLars Grefer <eclipse@larsgrefer.de>
Sat, 15 Aug 2020 14:30:09 +0000 (16:30 +0200)
committerLars Grefer <eclipse@larsgrefer.de>
Sat, 15 Aug 2020 14:36:00 +0000 (16:36 +0200)
commit3641f1626df6b9b1c11dd3f16b01a01495f4662d
tree2957ce458f23462b6ec0777ddded5d854233d880
parent2debfa05f43a6fe71e7bc141f4f78c66f85c95b0
Collection.toArray() call style

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 which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation.

Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
29 files changed:
ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java
ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java
bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/JavaClass.java
bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java
build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java
loadtime/src/main/java/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/BuildArgParser.java
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AstUtil.java
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseScope.java
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/InterTypeMemberFinder.java
org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java
org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/MemberImpl.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedType.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnnotationPatternList.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/BasicTokenSource.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/TypePatternList.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java
org.aspectj.matcher/src/test/java/org/aspectj/weaver/CommonWorldTests.java
org.aspectj.matcher/src/test/java/org/aspectj/weaver/TestUtils.java
taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/compilers/Ajc.java
testing/src/test/java/org/aspectj/testing/util/options/Values.java
util/src/main/java/org/aspectj/util/FileUtil.java
weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java
weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java
weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java
weaver/src/main/java/org/aspectj/weaver/tools/cache/AbstractIndexedFileCacheBacking.java