aherbert commented on PR #276:
URL: 
https://github.com/apache/commons-collections/pull/276#issuecomment-1489394606

   If you modify AbstractHashMap to just use the converted key in `put`:
   
   ```java
       protected void addMapping(final int hashIndex, final int hashCode, final 
K key, final V value) {
           addConvertedMapping(hashIndex, hashCode, convertKey(key), value);
       }
   
       protected void addConvertedMapping(final int hashIndex, final int 
hashCode, final Object convertedKey, final V value) {
           modCount++;
           final HashEntry<K, V> entry = createConvertedEntry(data[hashIndex], 
hashCode, convertedKey, value);
           addEntry(entry, hashIndex);
           size++;
           checkCapacity();
       }
   
       protected HashEntry<K, V> createConvertedEntry(final HashEntry<K, V> 
next, final int hashCode, final Object convertedKey, final V value) {
           return new HashEntry<>(next, hashCode, convertedKey, value);
       }
   ```
   
   With this change the existing `createEntry` method is not called in the 
codebase. The `LRUMap` and `MultiKeyMap` call `addMapping`.
   
   Any child classes that do override `convertKey` will inherit the performance 
change from `put`. Any classes that use `addMapping` will not see a performance 
change if they have converted the key already (or do not have to).
   
   Since this will not enhance the performance of any of the classes in 
Collections other than `CaseInsensitiveMap` then I do not see the point of 
adding more methods to the API and deprecating current ones. I think my 
suggestion on the Jira ticket to simply cache the converted key privately in 
`CaseInsensitiveMap` is the most conservative change. The new field to cache 
the converted key can be marked as `transient` to avoid serialisation issues. 
It just needs to be created before deserialisation by overriding `doReadObject`.
    


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to