harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r832653 - /harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
Date Wed, 04 Nov 2009 03:24:55 GMT
Author: qiuxx
Date: Wed Nov  4 03:24:54 2009
New Revision: 832653

URL: http://svn.apache.org/viewvc?rev=832653&view=rev
Log:
Class.getMethods() is time consuming, cache found methods of target class for java.beans.Statement
to avoid get the reflection data each time which results in accelerating the execution.

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java?rev=832653&r1=832652&r2=832653&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
Wed Nov  4 03:24:54 2009
@@ -29,6 +29,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.WeakHashMap;
 
 import org.apache.harmony.beans.internal.nls.Messages;
 
@@ -41,6 +42,9 @@
 
     private Object[] arguments;
     
+    // cache used methods of specified target class to accelerate method search
+    private static WeakHashMap<Class, Method[]> cache = new WeakHashMap<Class, Method[]>();
+    
     // the special method name donating constructors
     static final String CONSTRUCTOR_NAME = "new"; //$NON-NLS-1$
 
@@ -330,7 +334,15 @@
     static Method findMethod(Class<?> targetClass, String methodName, Object[] arguments,
             boolean methodIsStatic) throws NoSuchMethodException {
         Class<?>[] argClasses = getClasses(arguments);
-        Method[] methods = targetClass.getMethods();
+        Method[] methods = null;
+        
+        if(cache.containsKey(targetClass)){
+            methods = cache.get(targetClass);
+        }else{
+            methods = targetClass.getMethods();
+            cache.put(targetClass, methods);
+        }
+        
         ArrayList<Method> foundMethods = new ArrayList<Method>();
         Method[] foundMethodsArr;
         for (Method method : methods) {



Mime
View raw message