[ 
https://issues.apache.org/jira/browse/TAPESTRY-2165?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Marcus Schulte updated TAPESTRY-2165:
-------------------------------------

    Fix Version/s:     (was: 4.1.6)
                   4.1.7

> RecordUtils.iterateOverMatchingAttributes efficiency
> ----------------------------------------------------
>
>                 Key: TAPESTRY-2165
>                 URL: https://issues.apache.org/jira/browse/TAPESTRY-2165
>             Project: Tapestry
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: 4.1, 4.1.1, 4.1.2, 4.1.3, 4.1.5
>            Reporter: Daniel Caldeweyher
>            Priority: Minor
>             Fix For: 4.1.7
>
>
> The current implementation of RecordUtils.iterateOverMatchingAttributes is 
> not very efficient as it iterates over all session attributesnames and check 
> name.startWith(prefix) for every single one, basically an O(n) complexity. 
> Given an app with a lot of pages each with multiple persisted properties this 
> is not the best approach, considering that WebSession.getAttributeNames() 
> returns a sorted list of strings. Because of this we can improve efficiency 
> through binary search and shortcutting the search once we have passed the 
> last prefix-matching attribute. Just replace the current 
> iterateOverMatchingAttributes code:
>         String prefix = strategyId + "," + applicationId + "," + pageName + 
> ",";
>         Iterator i = session.getAttributeNames().iterator();
>         while (i.hasNext()) {
>             String name = (String)i.next();
>             if (name.startsWith(prefix)) callback.handleAttribute(session, 
> name);
>         }
> with:
>         String prefix = strategyId + "," + applicationId + "," + pageName + 
> ",";
>         List sessionAttributeNames = session.getAttributeNames(); //sorted
>         int pos = Collections.binarySearch(sessionAttributeNames, prefix);
>         if(pos < 0) {
>               pos = (-pos) - 1;
>         }
>         Iterator i = sessionAttributeNames.listIterator(pos);
>         while (i.hasNext()) {
>             String name = (String)i.next();
>             if (name.startsWith(prefix)) {
>                 callback.handleAttribute(session, name);
>             } else {
>               break;
>             }
>         }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to