Skip to content

Commit

Permalink
Cache parameterTypes in ReflectionUtils.hasCompatibleSignature()
Browse files Browse the repository at this point in the history
This commit avoids repeated cloning of the parameter types array.
  • Loading branch information
sbrannen committed Apr 7, 2024
1 parent 79ad45b commit c052455
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1803,15 +1803,16 @@ private static boolean hasCompatibleSignature(Method candidate, String methodNam
if (parameterTypes.length != candidate.getParameterCount()) {
return false;
}
Class<?>[] candidateParameterTypes = candidate.getParameterTypes();
// trivial case: parameter types exactly match
if (Arrays.equals(parameterTypes, candidate.getParameterTypes())) {
if (Arrays.equals(parameterTypes, candidateParameterTypes)) {
return true;
}
// param count is equal, but types do not match exactly: check for method sub-signatures
// https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2
for (int i = 0; i < parameterTypes.length; i++) {
Class<?> lowerType = parameterTypes[i];
Class<?> upperType = candidate.getParameterTypes()[i];
Class<?> upperType = candidateParameterTypes[i];
if (!upperType.isAssignableFrom(lowerType)) {
return false;
}
Expand Down

0 comments on commit c052455

Please sign in to comment.