From b4c8faf1fd66da5b80a1b68f4d4e560d9f8e7f28 Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 9 Jul 2011 23:43:53 +0200 Subject: [PATCH] cache the generics & accessors that XmlSerializer uses --- .../src/com/intellij/util/xmlb/BeanBinding.java | 14 +++++++++++++- .../com/intellij/util/xmlb/PropertyAccessor.java | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/platform/util/src/com/intellij/util/xmlb/BeanBinding.java b/platform/util/src/com/intellij/util/xmlb/BeanBinding.java index 948b39291cbe..fd7620a5ec58 100644 --- a/platform/util/src/com/intellij/util/xmlb/BeanBinding.java +++ b/platform/util/src/com/intellij/util/xmlb/BeanBinding.java @@ -22,6 +22,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.reference.SoftReference; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.MultiMap; import com.intellij.util.xmlb.annotations.*; @@ -35,10 +36,13 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; class BeanBinding implements Binding { private static final Logger LOG = Logger.getInstance("#com.intellij.util.xmlb.BeanBinding"); + private static final ConcurrentHashMap>> ourAccessorCache = new ConcurrentHashMap>>(); + private final String myTagName; private final Map myPropertyBindings = new HashMap(); private final List myPropertyBindingsList = new ArrayList(); @@ -196,7 +200,13 @@ class BeanBinding implements Binding { @NotNull static List getAccessors(Class aClass) { - final List accessors = Lists.newArrayList(); + final SoftReference> reference = ourAccessorCache.get(aClass); + List accessors = reference == null ? null : reference.get(); + if (accessors != null) { + return accessors; + } + + accessors = Lists.newArrayList(); final Map> candidates = Maps.newTreeMap(); // (name,(getter,setter)) for (Method method : aClass.getMethods()) { @@ -230,6 +240,8 @@ class BeanBinding implements Binding { } } + ourAccessorCache.put(aClass, new SoftReference>(accessors)); + return accessors; } diff --git a/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java b/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java index 401af2a52776..fdf60da18328 100644 --- a/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java +++ b/platform/util/src/com/intellij/util/xmlb/PropertyAccessor.java @@ -32,6 +32,7 @@ class PropertyAccessor implements Accessor { private final Class myType; private final Method myReadMethod; private final Method myWriteMethod; + private final Type myGenericType; public PropertyAccessor(PropertyDescriptor descriptor) { this(descriptor.getName(), descriptor.getPropertyType(), descriptor.getReadMethod(), descriptor.getWriteMethod()); @@ -42,6 +43,7 @@ class PropertyAccessor implements Accessor { myType = type; myReadMethod = readMethod; myWriteMethod = writeMethod; + myGenericType = myReadMethod.getGenericReturnType(); } public Object read(Object o) { @@ -91,7 +93,7 @@ class PropertyAccessor implements Accessor { } public Type getGenericType() { - return myReadMethod.getGenericReturnType(); + return myGenericType; } @NonNls