You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2001/05/28 07:07:37 UTC

cvs commit: jakarta-tomcat-jasper/jasper34/runtime/org/apache/jasper34/runtime JspRuntimeLibrary.java

costin      01/05/27 22:07:37

  Modified:    jasper34/runtime/org/apache/jasper34/runtime
                        JspRuntimeLibrary.java
  Log:
  Quick optimization for jsp:get/setProperty. Method lookup result
  is cached, as it is the most expensive part of method invocation.
  
  This can be quite easily put back into 3.3 - but I don't think it's
  a good idea: we'll have more tunnings and it'll save time to keep
  33 stable and just replace the whole thing when it has had enough testing.
  
  Revision  Changes    Path
  1.2       +37 -6     jakarta-tomcat-jasper/jasper34/runtime/org/apache/jasper34/runtime/JspRuntimeLibrary.java
  
  Index: JspRuntimeLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper34/runtime/org/apache/jasper34/runtime/JspRuntimeLibrary.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JspRuntimeLibrary.java	2001/05/27 23:09:20	1.1
  +++ JspRuntimeLibrary.java	2001/05/28 05:07:37	1.2
  @@ -60,6 +60,7 @@
   
   import java.io.IOException;
   import java.util.Enumeration;
  +import java.util.Hashtable;
   
   import java.lang.reflect.Method;
   
  @@ -216,6 +217,7 @@
       //-------------------------------------------------------------------
       // functions to convert builtin Java data types to string.
       //-------------------------------------------------------------------
  +    // Used by GetProperty 
       // __begin toStringMethod
       public static String toString(Object o) {
           return (o == null) ? "" : o.toString();
  @@ -540,11 +542,26 @@
   	    throw new JasperException(ex);
   	}	
       }
  +   
  +    public static Hashtable readMethodCache=new Hashtable();
  +    public static Hashtable writeMethodCache=new Hashtable();
       
  -    public static java.lang.reflect.Method getWriteMethod(Class beanClass, String prop)
  -    throws JasperException {
  +
  +    public static java.lang.reflect.Method getWriteMethod(Class beanClass,
  +							  String prop)
  +	throws JasperException
  +    {
   	java.lang.reflect.Method method = null;	
           Class type = null;
  +
  +	Hashtable methods=(Hashtable)writeMethodCache.get( beanClass );
  +	if( methods==null ) {
  +	    methods=new Hashtable();
  +	    writeMethodCache.put( beanClass, methods );
  +	}
  +	method=(java.lang.reflect.Method)methods.get( prop );
  +	if( method != null ) return method;
  +
   	try {
   	    java.beans.BeanInfo info
                   = java.beans.Introspector.getBeanInfo(beanClass);
  @@ -578,14 +595,27 @@
                           new Object[] {prop, beanClass.getName()}));
               }
           }
  +
  +	methods.put( prop, method );
           return method;
       }
   
  -    public static java.lang.reflect.Method getReadMethod(Class beanClass, String prop)
  -    throws JasperException {
  -        java.lang.reflect.Method method = null;        
  +    public static java.lang.reflect.Method getReadMethod(Class beanClass,
  +							 String prop)
  +	throws JasperException
  +    {
  +	java.lang.reflect.Method method = null;        
           Class type = null;
  -        try {
  +
  +	Hashtable methods=(Hashtable)readMethodCache.get( beanClass );
  +	if( methods==null ) {
  +	    methods=new Hashtable();
  +	    readMethodCache.put( beanClass, methods );
  +	}
  +	method=(java.lang.reflect.Method)methods.get( prop );
  +	if( method != null ) return method;
  +	
  +	try {
               java.beans.BeanInfo info
                   = java.beans.Introspector.getBeanInfo(beanClass);
               if ( info != null ) {
  @@ -619,6 +649,7 @@
               }
           }
   
  +	methods.put( prop, method );
   	return method;
       }