From e20614ed03a23092e39ab18bc37c04a18ecd1db8 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Mon, 16 Jan 2012 18:28:56 +0400 Subject: [PATCH] 7122740: PropertyDescriptor Performance Slow Reviewed-by: rupashka --- .../classes/com/sun/beans/TypeResolver.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/jdk/src/share/classes/com/sun/beans/TypeResolver.java b/jdk/src/share/classes/com/sun/beans/TypeResolver.java index 8660213a050..baba362c4bc 100644 --- a/jdk/src/share/classes/com/sun/beans/TypeResolver.java +++ b/jdk/src/share/classes/com/sun/beans/TypeResolver.java @@ -154,7 +154,7 @@ public final class TypeResolver { * @see #resolve(Type) */ public static Type resolve(Type actual, Type formal) { - return new TypeResolver(actual).resolve(formal); + return getTypeResolver(actual).resolve(formal); } /** @@ -169,7 +169,7 @@ public final class TypeResolver { * @see #resolve(Type[]) */ public static Type[] resolve(Type actual, Type[] formals) { - return new TypeResolver(actual).resolve(formals); + return getTypeResolver(actual).resolve(formals); } /** @@ -228,9 +228,20 @@ public final class TypeResolver { return classes; } + public static TypeResolver getTypeResolver(Type type) { + synchronized (CACHE) { + TypeResolver resolver = CACHE.get(type); + if (resolver == null) { + resolver = new TypeResolver(type); + CACHE.put(type, resolver); + } + return resolver; + } + } - private final Map, Type> map - = new HashMap, Type>(); + private static final WeakCache CACHE = new WeakCache<>(); + + private final Map, Type> map = new HashMap<>(); /** * Constructs the type resolver for the given actual type.