Cache AbstractBeanFactory.isFactoryBean results

Add an additional cache to the `RootBeanDefinition` to save
recalculating the result of `isFactoryBean`.

Closes gh-23337
This commit is contained in:
Phillip Webb
2019-07-18 11:48:32 +01:00
committed by Juergen Hoeller
parent 95edcb81b5
commit 527876d9a0
2 changed files with 12 additions and 2 deletions

View File

@@ -1333,6 +1333,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
ObjectUtils.nullSafeEquals(mbd.getFactoryMethodName(), previous.getFactoryMethodName()) &&
(mbd.targetType == null || mbd.targetType.equals(previous.targetType))) {
mbd.targetType = previous.targetType;
mbd.isFactoryBean = previous.isFactoryBean;
mbd.resolvedTargetType = previous.resolvedTargetType;
mbd.factoryMethodReturnType = previous.factoryMethodReturnType;
mbd.factoryMethodToIntrospect = previous.factoryMethodToIntrospect;
@@ -1541,8 +1542,13 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
* @param mbd the corresponding bean definition
*/
protected boolean isFactoryBean(String beanName, RootBeanDefinition mbd) {
Class<?> beanType = predictBeanType(beanName, mbd, FactoryBean.class);
return (beanType != null && FactoryBean.class.isAssignableFrom(beanType));
Boolean result = mbd.isFactoryBean;
if (result == null) {
Class<?> beanType = predictBeanType(beanName, mbd, FactoryBean.class);
result = beanType != null && FactoryBean.class.isAssignableFrom(beanType);
mbd.isFactoryBean = result;
}
return result;
}
/**

View File

@@ -74,6 +74,10 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
@Nullable
volatile Class<?> resolvedTargetType;
/** Package-visible field for caching if the bean is a factory bean. */
@Nullable
volatile Boolean isFactoryBean;
/** Package-visible field for caching the return type of a generically typed factory method. */
@Nullable
volatile ResolvableType factoryMethodReturnType;