Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b197aed

Browse filesBrowse files
committed
Cache uniqueDeclaredMethods
** Probably not for Spring 4 M1 **
1 parent a824fe3 commit b197aed
Copy full SHA for b197aed

File tree

Expand file treeCollapse file tree

1 file changed

+15
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-1
lines changed
Open diff view settings
Collapse file

‎spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java‎

Copy file name to clipboardExpand all lines: spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import org.springframework.core.ParameterNameDiscoverer;
7575
import org.springframework.core.PriorityOrdered;
7676
import org.springframework.util.ClassUtils;
77+
import org.springframework.util.ConcurrentReferenceHashMap;
7778
import org.springframework.util.ObjectUtils;
7879
import org.springframework.util.ReflectionUtils;
7980
import org.springframework.util.StringUtils;
@@ -151,6 +152,10 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
151152
private final Map<Class, PropertyDescriptor[]> filteredPropertyDescriptorsCache =
152153
new ConcurrentHashMap<Class, PropertyDescriptor[]>(64);
153154

155+
/** Cache of unique declared methods **/
156+
private final ConcurrentReferenceHashMap<Class, Method[]> uniqueDeclaredMethodsCache =
157+
new ConcurrentReferenceHashMap<Class, Method[]>();
158+
154159

155160
/**
156161
* Create a new AbstractAutowireCapableBeanFactory.
@@ -648,7 +653,7 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
648653
// If all factory methods have the same return type, return that type.
649654
// Can't clearly figure out exact method due to type converting / autowiring!
650655
int minNrOfArgs = mbd.getConstructorArgumentValues().getArgumentCount();
651-
Method[] candidates = ReflectionUtils.getUniqueDeclaredMethods(factoryClass);
656+
Method[] candidates = getUniqueDeclaredMethods(factoryClass);
652657
Set<Class<?>> returnTypes = new HashSet<Class<?>>(1);
653658
for (Method factoryMethod : candidates) {
654659
if (Modifier.isStatic(factoryMethod.getModifiers()) == isStatic &&
@@ -671,6 +676,15 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
671676
}
672677
}
673678

679+
private Method[] getUniqueDeclaredMethods(Class factoryClass) {
680+
Method[] methods = this.uniqueDeclaredMethodsCache.get(factoryClass);
681+
if(methods == null) {
682+
methods = ReflectionUtils.getUniqueDeclaredMethods(factoryClass);
683+
this.uniqueDeclaredMethodsCache.put(factoryClass, methods);
684+
}
685+
return methods;
686+
}
687+
674688
/**
675689
* This implementation attempts to query the FactoryBean's generic parameter metadata
676690
* if present to determine the object type. If not present, i.e. the FactoryBean is

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.