[
https://issues.apache.org/jira/browse/COLLECTIONS-803?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17706142#comment-17706142
]
Simulant commented on COLLECTIONS-803:
--------------------------------------
[~aherbert] Thank you for your feedback. I can follow the argumentation in your
last paragraph to only overwrite existing methods.
However, I struggle to implement it, as {{addMapping}} from AbstractHashedMap
requires the parameter {{key}} to be of the generic type {{K}}. I don't want to
change the behaviour and implementation of {{convertKey}}. It currently returns
a plain {{Object}}. I could cast the converted key to {{K}} because the strict
typing of generics is removed at runtime. But at compile time it looks just
wrong and when reading it, my first intention was that I would receive a
ClassCastException during runtime. But in my test cases it was not the case.
Do you think this code smell would be acceptable to have a cleaner API facing
outside?
> 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 50m
> 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.10#820010)