Skip to content

Avoid empty array allocations in AnnotationTypeMapping #33507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ final class AnnotationTypeMapping {

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

private static final int[] EMPTY_INT_ARRAY = new int[0];


@Nullable
private final AnnotationTypeMapping source;
Expand Down Expand Up @@ -606,6 +608,9 @@ boolean isSynthesizable() {


private static int[] filledIntArray(int size) {
if (size == 0) {
return EMPTY_INT_ARRAY;
}
int[] array = new int[size];
Arrays.fill(array, -1);
return array;
Expand Down Expand Up @@ -684,7 +689,7 @@ class MirrorSets {
private final MirrorSet[] assigned;

MirrorSets() {
this.assigned = new MirrorSet[attributes.size()];
this.assigned = attributes.size() > 0 ? new MirrorSet[attributes.size()] : EMPTY_MIRROR_SETS;
this.mirrorSets = EMPTY_MIRROR_SETS;
}

Expand Down Expand Up @@ -728,6 +733,9 @@ MirrorSet getAssigned(int attributeIndex) {
}

int[] resolve(@Nullable Object source, @Nullable Object annotation, ValueExtractor valueExtractor) {
if (attributes.size() == 0) {
return EMPTY_INT_ARRAY;
}
int[] result = new int[attributes.size()];
for (int i = 0; i < result.length; i++) {
result[i] = i;
Expand Down