Implement micro performance optimizations

- ClassUtils.isAssignable(): Avoid Map lookup when the type is not a
  primitive.

- AnnotationsScanner: Perform low cost array length check before String
  comparisons.

- BeanFactoryUtils: Use char comparison instead of String comparison.
  The bean factory prefix is '&', so we can use a char comparison
  instead of more heavyweight String.startsWith("&").

- AbstractBeanFactory.getMergedBeanDefinition(): Perform the low cost
  check first. Map lookup, while cheap, is still more expensive than
  instanceof.

Closes gh-34717

Signed-off-by: Olivier Bourgain <olivierbourgain02@gmail.com>
This commit is contained in:
Olivier Bourgain
2025-04-03 15:13:36 +02:00
committed by Sam Brannen
parent ee804ee8fb
commit 0f2308e85f
4 changed files with 14 additions and 5 deletions

View File

@@ -355,6 +355,7 @@ abstract class AnnotationsScanner {
private static boolean isOverride(Method rootMethod, Method candidateMethod) {
return (!Modifier.isPrivate(candidateMethod.getModifiers()) &&
candidateMethod.getParameterCount() == rootMethod.getParameterCount() &&
candidateMethod.getName().equals(rootMethod.getName()) &&
hasSameParameterTypes(rootMethod, candidateMethod));
}

View File

@@ -637,10 +637,11 @@ public abstract class ClassUtils {
Class<?> resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType);
return (lhsType == resolvedPrimitive);
}
else {
else if (rhsType.isPrimitive()) {
Class<?> resolvedWrapper = primitiveTypeToWrapperMap.get(rhsType);
return (resolvedWrapper != null && lhsType.isAssignableFrom(resolvedWrapper));
}
return false;
}
/**