Skip to content

Commit 052bbcc

Browse files
committed
Cache parameter types array in ClassUtils.findInterfaceMethodIfPossible()
1 parent f979166 commit 052bbcc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

spring-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,12 +1425,17 @@ public static Method getInterfaceMethodIfPossible(Method method, @Nullable Class
14251425
}
14261426

14271427
private static Method findInterfaceMethodIfPossible(Method method, Class<?> startClass, Class<?> endClass) {
1428+
Class<?>[] parameterTypes = null;
14281429
Class<?> current = startClass;
14291430
while (current != null && current != endClass) {
1430-
Class<?>[] ifcs = current.getInterfaces();
1431-
for (Class<?> ifc : ifcs) {
1431+
if (parameterTypes == null) {
1432+
// Since Method#getParameterTypes() clones the array, we lazily retrieve
1433+
// and cache parameter types to avoid cloning the array multiple times.
1434+
parameterTypes = method.getParameterTypes();
1435+
}
1436+
for (Class<?> ifc : current.getInterfaces()) {
14321437
try {
1433-
return ifc.getMethod(method.getName(), method.getParameterTypes());
1438+
return ifc.getMethod(method.getName(), parameterTypes);
14341439
}
14351440
catch (NoSuchMethodException ex) {
14361441
// ignore

0 commit comments

Comments
 (0)