aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1367686 - in /aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint: container/BeanRecipe.java utils/ReflectionUtils.java
Date Tue, 31 Jul 2012 17:23:51 GMT
Author: gnodet
Date: Tue Jul 31 17:23:51 2012
New Revision: 1367686

URL: http://svn.apache.org/viewvc?rev=1367686&view=rev
Log:
[ARIES-894] Cache values for performances

Modified:
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/ReflectionUtils.java

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java?rev=1367686&r1=1367685&r2=1367686&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
(original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
Tue Jul 31 17:23:51 2012
@@ -345,7 +345,7 @@ public class BeanRecipe extends Abstract
     private Map<Method, List<Object>> findMatchingMethods(Class type, String
name, boolean instance, List<Object> args, List<ReifiedType> types) {
         Map<Method, List<Object>> matches = new HashMap<Method, List<Object>>();
         // Get constructors
-        List<Method> methods = getPublicMethods(type);
+        List<Method> methods = new ArrayList<Method>(Arrays.asList(getPublicMethods(type)));
         // Discard any signature with wrong cardinality
         for (Iterator<Method> it = methods.iterator(); it.hasNext();) {
             Method mth = it.next();

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/ReflectionUtils.java?rev=1367686&r1=1367685&r2=1367686&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/ReflectionUtils.java
(original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/ReflectionUtils.java
Tue Jul 31 17:23:51 2012
@@ -53,6 +53,7 @@ import org.osgi.service.blueprint.contai
  */
 public class ReflectionUtils {
 
+    private static Map<Class<?>, WeakReference<Method[]>> publicMethods
= Collections.synchronizedMap(new WeakHashMap<Class<?>, WeakReference<Method[]>>());
     private static Map<Class<?>, PropertyDescriptor[][]> beanInfos = Collections.synchronizedMap(new
WeakHashMap<Class<?>, PropertyDescriptor[][]>());
 
     public static boolean hasDefaultConstructor(Class type) {
@@ -121,9 +122,15 @@ public class ReflectionUtils {
         return null;
     }
 
-    public static List<Method> getPublicMethods(Class clazz) {
-        ArrayList<Method> methods = new ArrayList<Method>();
-        doGetPublicMethods(clazz, methods);
+    public static Method[] getPublicMethods(Class clazz) {
+        WeakReference<Method[]> ref = publicMethods.get(clazz);
+        Method[] methods = ref != null ? ref.get() : null;
+        if (methods == null) {
+            ArrayList<Method> array = new ArrayList<Method>();
+            doGetPublicMethods(clazz, array);
+            methods = array.toArray(new Method[array.size()]);
+            publicMethods.put(clazz, new WeakReference<Method[]>(methods));
+        }
         return methods;
     }
 



Mime
View raw message