diff options
author | Andrey Turbanov <turbanoff@gmail.com> | 2021-12-18 15:20:43 +0300 |
---|---|---|
committer | Andrey Turbanov <turbanoff@gmail.com> | 2021-12-18 15:20:43 +0300 |
commit | 4c8c90de69b4e3cdeea0f598fea5a5358ac2c861 (patch) | |
tree | 6b1526b6d91bde9f3a1e00bace4e12cde6b6dfd4 /bcel-builder | |
parent | 4021ffcbfe320a1b91bb2bcee7a112f7122ef82d (diff) | |
download | aspectj-4c8c90de69b4e3cdeea0f598fea5a5358ac2c861.tar.gz aspectj-4c8c90de69b4e3cdeea0f598fea5a5358ac2c861.zip |
Reduce empty array allocations
Diffstat (limited to 'bcel-builder')
5 files changed, 9 insertions, 12 deletions
diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/FieldOrMethod.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/FieldOrMethod.java index 67f70e1b4..59e4d2b37 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/FieldOrMethod.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/FieldOrMethod.java @@ -177,7 +177,7 @@ public abstract class FieldOrMethod extends Modifiers implements Node { if (accumulatedAnnotations.size() == 0) { annotations = AnnotationGen.NO_ANNOTATIONS; } else { - annotations = accumulatedAnnotations.toArray(new AnnotationGen[] {}); + annotations = accumulatedAnnotations.toArray(AnnotationGen.NO_ANNOTATIONS); } } return annotations; diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/JavaClass.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/JavaClass.java index 0be2b8ae5..5d2ec65e5 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/JavaClass.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/JavaClass.java @@ -88,10 +88,7 @@ import org.aspectj.apache.bcel.util.SyntheticRepository; public class JavaClass extends Modifiers implements Cloneable, Node { private static final String[] NoInterfaceNames = new String[0]; - private static final Field[] NoFields = new Field[0]; - private static final Method[] NoMethod = new Method[0]; private static final int[] NoInterfaceIndices = new int[0]; - private static final Attribute[] NoAttributes = new Attribute[0]; private String fileName; private String packageName; @@ -141,9 +138,9 @@ public class JavaClass extends Modifiers implements Cloneable, Node { this.modifiers = access_flags; this.cpool = cpool; this.interfaces = interfaces; - this.fields = (fields == null ? NoFields : fields); - this.methods = (methods == null ? NoMethod : methods); - this.attributes = (attributes == null ? NoAttributes : attributes); + this.fields = (fields == null ? Field.NoFields : fields); + this.methods = (methods == null ? Method.NoMethods : methods); + this.attributes = (attributes == null ? Attribute.NoAttributes : attributes); annotationsOutOfDate = true; // Get source file name if available @@ -294,7 +291,7 @@ public class JavaClass extends Modifiers implements Cloneable, Node { accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); } } - annotations = accumulatedAnnotations.toArray(new AnnotationGen[] {}); + annotations = accumulatedAnnotations.toArray(AnnotationGen.NO_ANNOTATIONS); annotationsOutOfDate = false; } return annotations; diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Method.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Method.java index 316eaa4c9..8f9003744 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Method.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Method.java @@ -228,8 +228,8 @@ public final class Method extends FieldOrMethod { AnnotationGen[] invisibleOnes = null; for (int i = 0; i < parameterCount; i++) { int count = 0; - visibleOnes = new AnnotationGen[0]; - invisibleOnes = new AnnotationGen[0]; + visibleOnes = AnnotationGen.NO_ANNOTATIONS; + invisibleOnes = AnnotationGen.NO_ANNOTATIONS; if (parameterAnnotationsVis != null) { visibleOnes = parameterAnnotationsVis.getAnnotationsOnParameter(i); count += visibleOnes.length; diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Utility.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Utility.java index 921570515..6ac083bce 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Utility.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Utility.java @@ -709,7 +709,7 @@ public abstract class Utility { newAttributes.add(new RuntimeInvisParamAnnos(riaIndex, riaData.length, riaData, cp)); } - return newAttributes.toArray(new Attribute[] {}); + return newAttributes.toArray(Attribute.NoAttributes); } catch (IOException e) { System.err.println("IOException whilst processing parameter annotations"); e.printStackTrace(); diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java index fc8112858..ce4eb98ea 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/ClassGen.java @@ -195,7 +195,7 @@ public class ClassGen extends Modifiers implements Cloneable { ConstantPool cp = this.cpool.getFinalConstantPool(); return new JavaClass(classnameIndex, superclassnameIndex, filename, major, minor, modifiers, cp, interfaces, fields, - methods, attributes.toArray(new Attribute[0]));// OPTIMIZE avoid toArray()? + methods, attributes.toArray(Attribute.NoAttributes));// OPTIMIZE avoid toArray()? } public void addInterface(String name) { |