Bug 58545 - WsHandshakeRequest inefficient use of keySet
WsHandshakeRequest inefficient use of keySet
Status: RESOLVED FIXED
Product: Tomcat 8
Classification: Unclassified
Component: WebSocket
8.0.x-trunk
Macintosh Mac OS X 10.1
: P2 trivial (vote)
: ----
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2015-10-25 22:49 UTC by Anthony Whitford
Modified: 2015-10-26 17:39 UTC (History)
0 users



Attachments
Replaces inefficient use of keySet() with more efficient entrySet() (940 bytes, patch)
2015-10-25 22:49 UTC, Anthony Whitford
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Whitford 2015-10-25 22:49:41 UTC
Created attachment 33217 [details]
Replaces inefficient use of keySet() with more efficient entrySet()

In WsHandshakeRequest...

        for (String pathName : pathParams.keySet()) {
            newParameters.put(pathName,
                    Collections.unmodifiableList(
                            Arrays.asList(pathParams.get(pathName))));
        }


should be:

        for (Entry<String,String> entry : pathParams.entrySet()) {
            final String pathName = entry.getKey();
            newParameters.put(pathName,
                    Collections.unmodifiableList(
                            Arrays.asList(entry.getValue())));
        }

to avoid the extra lookup.

See http://findbugs.sourceforge.net/bugDescriptions.html#WMI_WRONG_MAP_ITERATOR
Comment 1 Violeta Georgieva 2015-10-26 17:39:29 UTC
Hi,

Thanks for the report and the patch.
I applied the same fix on other places in the code also.
The fix is available in trunk, 8.0.x (for 8.0.29 onwards) and 7.0.x (for 7.0.66
onwards)

Regards,
Violeta