From: Finn B. <bc...@us...> - 2000-12-05 18:52:53
|
Update of /cvsroot/jython/jython/org/python/core In directory slayer.i.sourceforge.net:/tmp/cvs-serv10973 Modified Files: PyJavaClass.java Log Message: Only call Class.getMethods() once (in this class), and pass the result down into setBeanInfoCustom() and setMethods(). This improves performance. Index: PyJavaClass.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyJavaClass.java,v retrieving revision 2.25 retrieving revision 2.26 diff -C2 -r2.25 -r2.26 *** PyJavaClass.java 2000/11/17 21:22:15 2.25 --- PyJavaClass.java 2000/12/05 18:52:48 2.26 *************** *** 103,109 **** __dict__ = d; try { ! setBeanInfoCustom(proxyClass); setFields(proxyClass); ! setMethods(proxyClass); } catch (SecurityException se) {} } --- 103,110 ---- __dict__ = d; try { ! Method[] methods = getAccessibleMethods(proxyClass); ! setBeanInfoCustom(proxyClass, methods); setFields(proxyClass); ! setMethods(proxyClass, methods); } catch (SecurityException se) {} } *************** *** 341,372 **** // returns just the public methods return c.getMethods(); ! // from here on out we know we must be using at least Java 1.2. ! // Note that an ArrayList would be better here because we don't ! // need access to be synchronized, but that would prevent this file ! // from being compiled on Java 1.1 (as opposed to being compilable, ! // but not having the feature available). ! java.util.Vector methods = new java.util.Vector(); ! while (c != null) { ! // get all declared methods for this class, mutate their ! // accessibility and pop it into the array for later ! Method[] declared = c.getDeclaredMethods(); ! for (int i=0; i < declared.length; i++) { ! // TBD: this is a permanent change. Should we provide a way to ! // restore the original accessibility flag? ! JavaAccessibility.setAccessible(declared[i], true); ! methods.addElement(declared[i]); ! } ! // walk down superclass chain ! c = c.getSuperclass(); } ! // return (Method[])methods.toArray(new Method[methods.size()]); ! Method[] ret = new Method[methods.size()]; ! methods.copyInto(ret); ! return ret; } /* Add all methods declared by this class */ ! private void setMethods(Class c) { ! Method[] methods = getAccessibleMethods(c); for (int i=0; i<methods.length; i++) { Method method = methods[i]; --- 342,356 ---- // returns just the public methods return c.getMethods(); ! Method[] declared = c.getDeclaredMethods(); ! for (int i=0; i < declared.length; i++) { ! // TBD: this is a permanent change. Should we provide a way to ! // restore the original accessibility flag? ! JavaAccessibility.setAccessible(declared[i], true); } ! return declared; } /* Add all methods declared by this class */ ! private void setMethods(Class c, Method[] methods) { for (int i=0; i<methods.length; i++) { Method method = methods[i]; *************** *** 475,482 **** // This method is a workaround for Netscape's stupid security bug! ! private void setBeanInfoCustom(Class c) { //try { - Method[] meths = c.getMethods(); - int i; int n = meths.length; --- 459,464 ---- // This method is a workaround for Netscape's stupid security bug! ! private void setBeanInfoCustom(Class c, Method[] meths) { //try { int i; int n = meths.length; *************** *** 598,602 **** return c.getConstructors(); // return all constructors ! return c.getDeclaredConstructors(); } --- 580,592 ---- return c.getConstructors(); // return all constructors ! ! ! Constructor[] declared = c.getDeclaredConstructors(); ! for (int i=0; i < declared.length; i++) { ! // TBD: this is a permanent change. Should we provide a way to ! // restore the original accessibility flag? ! JavaAccessibility.setAccessible(declared[i], true); ! } ! return declared; } |