Skip to content

Commit

Permalink
Avoid empty array allocations in ResolvableType
Browse files Browse the repository at this point in the history
Avoid allocating empty arrays in a few places in ResolvableType.
  • Loading branch information
kilink committed Sep 4, 2024
1 parent daba9e5 commit 9a46879
Showing 1 changed file with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,14 @@ public ResolvableType[] getInterfaces() {
ResolvableType[] interfaces = this.interfaces;
if (interfaces == null) {
Type[] genericIfcs = resolved.getGenericInterfaces();
interfaces = new ResolvableType[genericIfcs.length];
for (int i = 0; i < genericIfcs.length; i++) {
interfaces[i] = forType(genericIfcs[i], this);
if (genericIfcs.length > 0) {
interfaces = new ResolvableType[genericIfcs.length];
for (int i = 0; i < genericIfcs.length; i++) {
interfaces[i] = forType(genericIfcs[i], this);
}
}
else {
interfaces = EMPTY_TYPES_ARRAY;
}
this.interfaces = interfaces;
}
Expand Down Expand Up @@ -789,16 +794,26 @@ public ResolvableType[] getGenerics() {
if (generics == null) {
if (this.type instanceof Class<?> clazz) {
Type[] typeParams = clazz.getTypeParameters();
generics = new ResolvableType[typeParams.length];
for (int i = 0; i < generics.length; i++) {
generics[i] = ResolvableType.forType(typeParams[i], this);
if (typeParams.length > 0) {
generics = new ResolvableType[typeParams.length];
for (int i = 0; i < generics.length; i++) {
generics[i] = ResolvableType.forType(typeParams[i], this);
}
}
else {
generics = EMPTY_TYPES_ARRAY;
}
}
else if (this.type instanceof ParameterizedType parameterizedType) {
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
generics = new ResolvableType[actualTypeArguments.length];
for (int i = 0; i < actualTypeArguments.length; i++) {
generics[i] = forType(actualTypeArguments[i], this.variableResolver);
if (actualTypeArguments.length > 0) {
generics = new ResolvableType[actualTypeArguments.length];
for (int i = 0; i < actualTypeArguments.length; i++) {
generics[i] = forType(actualTypeArguments[i], this.variableResolver);
}
}
else {
generics = EMPTY_TYPES_ARRAY;
}
}
else {
Expand Down

0 comments on commit 9a46879

Please sign in to comment.