aboutsummaryrefslogtreecommitdiffstats
path: root/weaver
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 /weaver
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 'weaver')
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java2
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java2
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java2
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/tools/cache/AbstractIndexedFileCacheBacking.java2
4 files changed, 4 insertions, 4 deletions
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java b/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java
index 96222fba2..5f2032704 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/AtAjAttributes.java
@@ -1905,7 +1905,7 @@ public class AtAjAttributes {
ignores.add(formalBinding.getName());
}
}
- pointcut.m_ignoreUnboundBindingForNames = ignores.toArray(new String[ignores.size()]);
+ pointcut.m_ignoreUnboundBindingForNames = ignores.toArray(new String[0]);
}
/**
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java
index 47984dfdf..922769dc0 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelObjectType.java
@@ -399,7 +399,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
if (pointcuts.size() == 0) {
this.pointcuts = ResolvedPointcutDefinition.NO_POINTCUTS;
} else {
- this.pointcuts = pointcuts.toArray(new ResolvedPointcutDefinition[pointcuts.size()]);
+ this.pointcuts = pointcuts.toArray(new ResolvedPointcutDefinition[0]);
}
resolveAnnotationDeclares(l);
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java
index 3ab0c5daf..7e2541e6c 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyMethodGen.java
@@ -336,7 +336,7 @@ public final class LazyMethodGen implements Traceable {
public AnnotationAJ[] getAnnotations() {
initialize();
if (memberView == null && newAnnotations!=null && newAnnotations.size()!=0) {
- return newAnnotations.toArray(new AnnotationAJ[newAnnotations.size()]);
+ return newAnnotations.toArray(new AnnotationAJ[0]);
}
return null;
}
diff --git a/weaver/src/main/java/org/aspectj/weaver/tools/cache/AbstractIndexedFileCacheBacking.java b/weaver/src/main/java/org/aspectj/weaver/tools/cache/AbstractIndexedFileCacheBacking.java
index cb05b10e0..32dba3d90 100644
--- a/weaver/src/main/java/org/aspectj/weaver/tools/cache/AbstractIndexedFileCacheBacking.java
+++ b/weaver/src/main/java/org/aspectj/weaver/tools/cache/AbstractIndexedFileCacheBacking.java
@@ -71,7 +71,7 @@ public abstract class AbstractIndexedFileCacheBacking extends AbstractFileCacheB
if (matches.isEmpty()) {
return EMPTY_KEYS;
} else {
- return matches.toArray(new String[matches.size()]);
+ return matches.toArray(new String[0]);
}
}