Browse Source

Cache attribute methods in AnnotationUtils

Issue: SPR-11512
pull/808/head
Sam Brannen 10 years ago
parent
commit
8ecae8697a
  1. 14
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

14
spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

@ -121,6 +121,9 @@ public abstract class AnnotationUtils {
private static final Map<Class<? extends Annotation>, Map<String, String>> attributeAliasesCache = private static final Map<Class<? extends Annotation>, Map<String, String>> attributeAliasesCache =
new ConcurrentReferenceHashMap<Class<? extends Annotation>, Map<String, String>>(256); new ConcurrentReferenceHashMap<Class<? extends Annotation>, Map<String, String>>(256);
private static final Map<Class<? extends Annotation>, List<Method>> attributeMethodsCache =
new ConcurrentReferenceHashMap<Class<? extends Annotation>, List<Method>>(256);
private static transient Log logger; private static transient Log logger;
@ -1311,13 +1314,22 @@ public abstract class AnnotationUtils {
* @since 4.2 * @since 4.2
*/ */
static List<Method> getAttributeMethods(Class<? extends Annotation> annotationType) { static List<Method> getAttributeMethods(Class<? extends Annotation> annotationType) {
List<Method> methods = new ArrayList<Method>();
List<Method> methods = attributeMethodsCache.get(annotationType);
if (methods != null) {
return methods;
}
methods = new ArrayList<Method>();
for (Method method : annotationType.getDeclaredMethods()) { for (Method method : annotationType.getDeclaredMethods()) {
if ((method.getParameterTypes().length == 0) && (method.getReturnType() != void.class)) { if ((method.getParameterTypes().length == 0) && (method.getReturnType() != void.class)) {
ReflectionUtils.makeAccessible(method); ReflectionUtils.makeAccessible(method);
methods.add(method); methods.add(method);
} }
} }
attributeMethodsCache.put(annotationType, methods);
return methods; return methods;
} }

Loading…
Cancel
Save