From bd787769be49fb935648330daa68bece2775eeea Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 22 May 2015 21:40:36 +0200 Subject: [PATCH] Introduce "synthesizable" cache in AnnotationUtils Issue: SPR-11512 --- .../core/annotation/AnnotationUtils.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 89d291a83d..7e602c099c 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -115,6 +115,9 @@ public abstract class AnnotationUtils { private static final Map, Boolean> annotatedInterfaceCache = new ConcurrentReferenceHashMap, Boolean>(256); + private static final Map, Boolean> synthesizableCache = + new ConcurrentReferenceHashMap, Boolean>(256); + private static transient Log logger; @@ -1074,9 +1077,17 @@ public abstract class AnnotationUtils { @SuppressWarnings("unchecked") private static boolean isSynthesizable(Class annotationType) { + Boolean flag = synthesizableCache.get(annotationType); + if (flag != null) { + return flag.booleanValue(); + } + + Boolean synthesizable = Boolean.FALSE; + for (Method attribute : getAttributeMethods(annotationType)) { if (getAliasedAttributeName(attribute) != null) { - return true; + synthesizable = Boolean.TRUE; + break; } Class returnType = attribute.getReturnType(); @@ -1084,18 +1095,22 @@ public abstract class AnnotationUtils { if (Annotation[].class.isAssignableFrom(returnType)) { Class nestedAnnotationType = (Class) returnType.getComponentType(); if (isSynthesizable(nestedAnnotationType)) { - return true; + synthesizable = Boolean.TRUE; + break; } } else if (Annotation.class.isAssignableFrom(returnType)) { Class nestedAnnotationType = (Class) returnType; if (isSynthesizable(nestedAnnotationType)) { - return true; + synthesizable = Boolean.TRUE; + break; } } } - return false; + synthesizableCache.put(annotationType, synthesizable); + + return synthesizable.booleanValue(); } /**