Skip to content

Commit 7827188

Browse files
kilinksdeleuze
authored andcommitted
Avoid empty array allocations in AnnotationTypeMapping
Closes gh-33507
1 parent 2b9b581 commit 7827188

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMapping.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ final class AnnotationTypeMapping {
6969

7070
private static final MirrorSet[] EMPTY_MIRROR_SETS = new MirrorSet[0];
7171

72+
private static final int[] EMPTY_INT_ARRAY = new int[0];
73+
7274

7375
@Nullable
7476
private final AnnotationTypeMapping source;
@@ -606,6 +608,9 @@ boolean isSynthesizable() {
606608

607609

608610
private static int[] filledIntArray(int size) {
611+
if (size == 0) {
612+
return EMPTY_INT_ARRAY;
613+
}
609614
int[] array = new int[size];
610615
Arrays.fill(array, -1);
611616
return array;
@@ -684,7 +689,7 @@ class MirrorSets {
684689
private final MirrorSet[] assigned;
685690

686691
MirrorSets() {
687-
this.assigned = new MirrorSet[attributes.size()];
692+
this.assigned = attributes.size() > 0 ? new MirrorSet[attributes.size()] : EMPTY_MIRROR_SETS;
688693
this.mirrorSets = EMPTY_MIRROR_SETS;
689694
}
690695

@@ -728,6 +733,9 @@ MirrorSet getAssigned(int attributeIndex) {
728733
}
729734

730735
int[] resolve(@Nullable Object source, @Nullable Object annotation, ValueExtractor valueExtractor) {
736+
if (attributes.size() == 0) {
737+
return EMPTY_INT_ARRAY;
738+
}
731739
int[] result = new int[attributes.size()];
732740
for (int i = 0; i < result.length; i++) {
733741
result[i] = i;

0 commit comments

Comments
 (0)