Details
-
Improvement
-
Status: Closed
-
Trivial
-
Resolution: Fixed
-
1.0
-
None
-
None
-
Any
Description
Noted that iteration through pd[] array thrice: twice to eliminate() the "empty" and "class" entries, and lastly to add each remaining entry to the descriptors map. The first two iterations each include costly array copies.
Guessed that two if name.equals checks in the third iteration would tend to be much quicker (especially for Beans with many properties). Did some quick performance checks to verify that this is the case - it's enough of a change to warrant a small refactor.
Here's a revised initialize(). You can thus remove the eliminate() method...
// Retrieve the set of property descriptors for this Context class
try
catch (IntrospectionException e)
{ pd = new PropertyDescriptor[0]; // Should never happen } // Initialize the underlying Map contents
if (pd.length > 0) {
descriptors = new HashMap();
for (int i = 0; i < pd.length; i++) {
String name = pd[i].getName();
if ("class".equals(name) || "empty".equals(name))
else
{ descriptors.put(name, pd[i]); super.put(name, singleton); } }
}
}