[ 
https://issues.apache.org/jira/browse/COLLECTIONS-803?focusedWorklogId=732552&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-732552
 ]

ASF GitHub Bot logged work on COLLECTIONS-803:
----------------------------------------------

                Author: ASF GitHub Bot
            Created on: 24/Feb/22 18:07
            Start Date: 24/Feb/22 18:07
    Worklog Time Spent: 10m 
      Work Description: freya022 commented on pull request #276:
URL: 
https://github.com/apache/commons-collections/pull/276#issuecomment-1050121979


   I may also suggest changing the `convertKey` method to use 
`key.toString().toLowerCase(Locale.ROOT)` to convert the non-null key, instead 
of the char loop.
   
   Benefits include better performance (measured a 2 times increase on my pc), 
and this is more fitted for the use case, as per the [Character#toLowerCase 
documentation](https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#toLowerCase(char)):
   
   ```
   In general, String.toLowerCase() should be used to map characters to 
lowercase. 
   String case mapping methods have several benefits over Character case 
mapping methods. 
   String case mapping methods can perform locale-sensitive mappings, 
context-sensitive mappings, and 1:M character mappings, whereas the Character 
case mapping methods cannot
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 732552)
    Time Spent: 1h  (was: 50m)

> CaseInsensitiveMap prevent duplicate key conversion on put
> ----------------------------------------------------------
>
>                 Key: COLLECTIONS-803
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-803
>             Project: Commons Collections
>          Issue Type: Improvement
>          Components: Map
>    Affects Versions: 4.4
>            Reporter: Simulant
>            Priority: Minor
>              Labels: performance
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> When adding a new item into a {{CaseInsensitiveMap}} the {{convertKey(key)}} 
> method is called twice, once in the {{put(key, value)}} method and second in 
> the {{createEntry(next, hashCode, key, value)}} method. The result could be 
> re-used resulting in a better performance.
> Depending on the {{toString()}} implementation of the key and the resulting 
> length of the key before the lower case conversion the operation can get 
> expensive and should not be called twice, as the {{CaseInsensitiveMap}} 
> overwrites the {{convertKey(key)}} method and makes it more expensive and 
> depending on the input unlike in the implementation of the 
> {{AbstractHashedMap}}.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to