[ http://issues.apache.org/jira/browse/CHAIN-32?page=all ]
Niall Pemberton resolved CHAIN-32:
----------------------------------
Fix Version: 1.2
Resolution: Fixed
Assign To: Niall Pemberton
Thanks for the patch - I applied a slight variation on what you suggested since
removing the calls to the "eliminate" method means that there will always be a
pd array of at least 2 and your implementation resulted in unnecessarily
creating an empty Map when there were no properties.
> Improve instantiation performance of ContextBase subclasses
> -----------------------------------------------------------
>
> Key: CHAIN-32
> URL: http://issues.apache.org/jira/browse/CHAIN-32
> Project: Commons Chain
> Type: Improvement
> Versions: 1.0 Release
> Environment: Any
> Reporter: Joshua Graham
> Assignee: Niall Pemberton
> Priority: Trivial
> Fix For: 1.2
>
> 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 {
> pd = Introspector.getBeanInfo
> (getClass()).getPropertyDescriptors();
> } 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)) {
> // skip getClass() and isEmpty();
> }
> else {
> descriptors.put(name, pd[i]);
> super.put(name, singleton);
> }
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]