harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r825974 - in /harmony/enhanced/classlib/trunk/modules/beans/src/main/java: java/beans/ org/apache/harmony/beans/ org/apache/harmony/beans/editors/
Date Fri, 16 Oct 2009 16:04:38 GMT
Author: odeakin
Date: Fri Oct 16 16:04:34 2009
New Revision: 825974

URL: http://svn.apache.org/viewvc?rev=825974&view=rev
Log:
Fix some performance issues flagged by FindBugs:
 - use static valueOf() instead of new Integer() etc constructors.
 - Instead of iterating over the keyset of a HashMap, iterate over the entrySet. This saves
another lookup of the value once you have the key.

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ArrayPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PrimitiveWrapperPersistenceDelegate.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyChangeSupport.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/Command.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/BooleanEditor.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ArrayPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ArrayPersistenceDelegate.java?rev=825974&r1=825973&r2=825974&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ArrayPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/ArrayPersistenceDelegate.java
Fri Oct 16 16:04:34 2009
@@ -38,7 +38,7 @@
         Class<?> componentType = oldInstance.getClass().getComponentType();
 
         return new Expression(oldInstance, Array.class, "newInstance", //$NON-NLS-1$
-                new Object[] { componentType, new Integer(length) });
+                new Object[] { componentType, Integer.valueOf(length) });
     }
 
     @Override
@@ -58,7 +58,7 @@
             Object newValue = Array.get(newInstance, i);
             if (!deepEquals(oldValue, newValue)) {
                 Statement s = new Statement(oldInstance, "set", //$NON-NLS-1$
-                                            new Object[] { new Integer(i), oldValue });
+                                            new Object[] { Integer.valueOf(i), oldValue });
                 out.writeStatement(s);
             }
         }

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PrimitiveWrapperPersistenceDelegate.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PrimitiveWrapperPersistenceDelegate.java?rev=825974&r1=825973&r2=825974&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PrimitiveWrapperPersistenceDelegate.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PrimitiveWrapperPersistenceDelegate.java
Fri Oct 16 16:04:34 2009
@@ -44,7 +44,7 @@
     protected Expression instantiate(Object oldInstance, Encoder enc) {
         if (oldInstance instanceof Character) {
             return new Expression(oldInstance, oldInstance.toString(),
-                    "charAt", new Object[] { new Integer(0) }); //$NON-NLS-1$
+                    "charAt", new Object[] { Integer.valueOf(0) }); //$NON-NLS-1$
         }
         return new Expression(oldInstance, oldInstance.getClass(),
                 "new", new Object[] { oldInstance //$NON-NLS-1$

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyChangeSupport.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyChangeSupport.java?rev=825974&r1=825973&r2=825974&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyChangeSupport.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyChangeSupport.java
Fri Oct 16 16:04:34 2009
@@ -137,7 +137,7 @@
 
         if (oldValue != newValue) {
             fireIndexedPropertyChange(propertyName, index,
-                    new Integer(oldValue), new Integer(newValue));
+                    Integer.valueOf(oldValue), Integer.valueOf(newValue));
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java?rev=825974&r1=825973&r2=825974&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
Fri Oct 16 16:04:34 2009
@@ -28,7 +28,7 @@
 import java.util.EventListener;
 import java.util.EventObject;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.Map;
 import java.util.TooManyListenersException;
 
 class StandardBeanInfo extends SimpleBeanInfo {
@@ -621,10 +621,9 @@
         // Put the properties found into the PropertyDescriptor array
         ArrayList<PropertyDescriptor> propertyList = new ArrayList<PropertyDescriptor>();
 
-        Iterator<String> keys = propertyTable.keySet().iterator();
-        while (keys.hasNext()) {
-            String propertyName = keys.next();
-            HashMap table = propertyTable.get(propertyName);
+        for (Map.Entry<String, HashMap> entry : propertyTable.entrySet()) {
+            String propertyName = entry.getKey();
+            HashMap table = entry.getValue();
             if (table == null) {
                 continue;
             }
@@ -848,8 +847,8 @@
             return;
         }
 
-        for (String key : propertyTable.keySet()) {
-            HashMap<String, Object> table = propertyTable.get(key);
+        for (Map.Entry<String, HashMap> entry : propertyTable.entrySet()) {
+            HashMap<String, Object> table = entry.getValue();
             ArrayList<Method> getters = (ArrayList<Method>) table.get(STR_GETTERS);
             ArrayList<Method> setters = (ArrayList<Method>) table.get(STR_SETTERS);
 
@@ -1074,10 +1073,8 @@
         }
 
         ArrayList<EventSetDescriptor> eventList = new ArrayList<EventSetDescriptor>();
-        Iterator<String> keys = eventTable.keySet().iterator();
-        while (keys.hasNext()) {
-            String key = keys.next();
-            HashMap table = eventTable.get(key);
+        for (Map.Entry<String, HashMap> entry : eventTable.entrySet()) {
+            HashMap table = entry.getValue();
             Method add = (Method) table.get(PREFIX_ADD);
             Method remove = (Method) table.get(PREFIX_REMOVE);
 
@@ -1089,7 +1086,7 @@
             Class<?> listenerType = (Class) table.get("listenerType"); //$NON-NLS-1$
             Method[] listenerMethods = (Method[]) table.get("listenerMethods"); //$NON-NLS-1$
             EventSetDescriptor eventSetDescriptor = new EventSetDescriptor(
-                    decapitalize(key), listenerType, listenerMethods, add,
+                    decapitalize(entry.getKey()), listenerType, listenerMethods, add,
                     remove, get);
 
             eventSetDescriptor.setUnicast(table.get("isUnicast") != null); //$NON-NLS-1$

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java?rev=825974&r1=825973&r2=825974&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/XMLDecoder.java
Fri Oct 16 16:04:34 2009
@@ -465,7 +465,7 @@
             } else if ("byte".equals(tag)) {
                 return Byte.valueOf(value);
             } else if ("char".equals(tag)) {
-                return new Character(value.charAt(0));
+                return Character.valueOf(value.charAt(0));
             } else if ("double".equals(tag)) {
                 return Double.valueOf(value);
             } else if ("float".equals(tag)) {

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/Command.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/Command.java?rev=825974&r1=825973&r2=825974&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/Command.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/Command.java
Fri Oct 16 16:04:34 2009
@@ -303,7 +303,7 @@
                                 statements = new Statement[operations.size()];
                             }
                             statements[i] = new Statement(getResultValue(),
-                                    "set", new Object[] { new Integer(i), //$NON-NLS-1$
+                                    "set", new Object[] { Integer.valueOf(i), //$NON-NLS-1$
                                             cmd.getResultValue() });
                             if ((i + 1) == operations.size()) {
                                 for (int j = 0; j < operations.size(); ++j) {
@@ -529,7 +529,7 @@
                                 "beans.43", //$NON-NLS-1$
                                 data));
                     }
-                    addArgument(new Argument(char.class, new Character(data
+                    addArgument(new Argument(char.class, Character.valueOf(data
                             .charAt(0))), 0);
                 } else {
                     addArgument(new Argument(String.class, data), 0);
@@ -542,7 +542,7 @@
                 int length = hasAttr("length") ? Integer //$NON-NLS-1$
                         .parseInt(getAttr("length")) : getArgumentsNumber(); //$NON-NLS-1$
                 copyArgumentsToCommands();
-                addArgument(new Argument(int.class, new Integer(length)), 0);
+                addArgument(new Argument(int.class, Integer.valueOf(length)), 0);
             } else if (hasAttr("property")) { //$NON-NLS-1$
                 String propertyValue = getAttr("property"); //$NON-NLS-1$
                 if (hasAttr("index")) { //$NON-NLS-1$

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/BooleanEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/BooleanEditor.java?rev=825974&r1=825973&r2=825974&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/BooleanEditor.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/BooleanEditor.java
Fri Oct 16 16:04:34 2009
@@ -35,7 +35,7 @@
             throw new NullPointerException();
         }
         if(text.equalsIgnoreCase("true") || text.equalsIgnoreCase("false")){
-            setValue(new Boolean(text));
+            setValue(Boolean.valueOf(text));
         }else{
             throw new IllegalArgumentException(text);
         }



Mime
View raw message