[ 
https://issues.apache.org/jira/browse/COLLECTIONS-878?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18030451#comment-18030451
 ] 

Gary D. Gregory commented on COLLECTIONS-878:
---------------------------------------------

[~safronovms] 

Please see my comment in the PR.

 

> Wrong capacity calculation leads to extra resize in MapUtils.invertMap
> ----------------------------------------------------------------------
>
>                 Key: COLLECTIONS-878
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-878
>             Project: Commons Collections
>          Issue Type: Improvement
>          Components: Map
>         Environment: Doesn't matter
>            Reporter: Safronov Maxim
>            Assignee: Gary D. Gregory
>            Priority: Trivial
>              Labels: easyfix, performance
>
> MapUtils.invertMap create map with the same size via HashMap constructor with 
> wrong capacity parameter. The capacity must be calculated as in new static 
> factory method HashMap.newHashMap (since 19). Old size must be divided to 
> load factor, in our case DEFAULT_LOAD_FACTOR 0.75 that casted to double. 
> Otherwise we have 50% probability that our map will be extra resized during 
> insertion of inverted entries. Expensive operation.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to