aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorLars Grefer <eclipse@larsgrefer.de>2020-08-15 16:30:09 +0200
committerLars Grefer <eclipse@larsgrefer.de>2020-08-15 16:36:00 +0200
commit3641f1626df6b9b1c11dd3f16b01a01495f4662d (patch)
tree2957ce458f23462b6ec0777ddded5d854233d880 /build
parent2debfa05f43a6fe71e7bc141f4f78c66f85c95b0 (diff)
downloadaspectj-3641f1626df6b9b1c11dd3f16b01a01495f4662d.tar.gz
aspectj-3641f1626df6b9b1c11dd3f16b01a01495f4662d.zip
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>
Diffstat (limited to 'build')
-rw-r--r--build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java4
1 files changed, 2 insertions, 2 deletions
diff --git a/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java b/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java
index ce7f2ce27..86782563f 100644
--- a/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java
+++ b/build/src/main/java/org/aspectj/internal/tools/build/SampleGatherer.java
@@ -221,7 +221,7 @@ public class SampleGatherer {
source,
startLine,
endLine,
- flags.toArray(new String[flags.size()]));
+ flags.toArray(new String[0]));
sink.addSample(sample);
// back to seeking start
@@ -978,7 +978,7 @@ class SampleUtil {
}
next = anchorName.substring(start);
result.add(next);
- return result.toArray(new String[result.size()]);
+ return result.toArray(new String[0]);
}
/**
* Replace literals with literals in source string