8245678: Avoid allocations in Executable.getAllGenericParameterTypes

Reviewed-by: jlaskey, redestad
This commit is contained in:
Christoph Dreis 2020-05-25 22:26:18 +02:00 committed by Claes Redestad
parent 742d35e08a
commit bc822ffad8

View File

@ -307,12 +307,12 @@ public abstract class Executable extends AccessibleObject
final boolean realParamData = hasRealParameterData();
final Type[] genericParamTypes = getGenericParameterTypes();
final Type[] nonGenericParamTypes = getParameterTypes();
final Type[] out = new Type[nonGenericParamTypes.length];
final Parameter[] params = getParameters();
int fromidx = 0;
// If we have real parameter data, then we use the
// synthetic and mandate flags to our advantage.
if (realParamData) {
final Type[] out = new Type[nonGenericParamTypes.length];
final Parameter[] params = getParameters();
int fromidx = 0;
for (int i = 0; i < out.length; i++) {
final Parameter param = params[i];
if (param.isSynthetic() || param.isImplicit()) {
@ -325,6 +325,7 @@ public abstract class Executable extends AccessibleObject
fromidx++;
}
}
return out;
} else {
// Otherwise, use the non-generic parameter data.
// Without method parameter reflection data, we have
@ -334,7 +335,6 @@ public abstract class Executable extends AccessibleObject
return genericParamTypes.length == nonGenericParamTypes.length ?
genericParamTypes : nonGenericParamTypes;
}
return out;
}
}