Optimize ClassUtils#getMostSpecificMethod
This commit optimizes ClassUtils#getMostSpecificMethod which is a method frequently invoked in typical Spring applications. It refines ClassUtils#isOverridable by considering static and final modifiers as non overridable and optimizes its implementation. Closes gh-30272
This commit is contained in:
@@ -50,6 +50,7 @@ import org.springframework.lang.Nullable;
|
|||||||
* @author Keith Donald
|
* @author Keith Donald
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
|
* @author Sebastien Deleuze
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
* @see TypeUtils
|
* @see TypeUtils
|
||||||
* @see ReflectionUtils
|
* @see ReflectionUtils
|
||||||
@@ -83,6 +84,12 @@ public abstract class ClassUtils {
|
|||||||
/** The ".class" file suffix. */
|
/** The ".class" file suffix. */
|
||||||
public static final String CLASS_FILE_SUFFIX = ".class";
|
public static final String CLASS_FILE_SUFFIX = ".class";
|
||||||
|
|
||||||
|
/** Precomputed value for the combination of private, static and final modifiers. */
|
||||||
|
private static final int NON_OVERRIDABLE_MODIFIER = Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL;
|
||||||
|
|
||||||
|
/** Precomputed value for the combination of public and protected modifiers. */
|
||||||
|
private static final int OVERRIDABLE_MODIFIER = Modifier.PUBLIC | Modifier.PROTECTED;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map with primitive wrapper type as key and corresponding primitive
|
* Map with primitive wrapper type as key and corresponding primitive
|
||||||
@@ -1396,10 +1403,10 @@ public abstract class ClassUtils {
|
|||||||
* @param targetClass the target class to check against
|
* @param targetClass the target class to check against
|
||||||
*/
|
*/
|
||||||
private static boolean isOverridable(Method method, @Nullable Class<?> targetClass) {
|
private static boolean isOverridable(Method method, @Nullable Class<?> targetClass) {
|
||||||
if (Modifier.isPrivate(method.getModifiers())) {
|
if ((method.getModifiers() & NON_OVERRIDABLE_MODIFIER) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Modifier.isPublic(method.getModifiers()) || Modifier.isProtected(method.getModifiers())) {
|
if ((method.getModifiers() & OVERRIDABLE_MODIFIER) != 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return (targetClass == null ||
|
return (targetClass == null ||
|
||||||
|
|||||||
Reference in New Issue
Block a user