[jira] [Commented] (COLLECTIONS-602) Improve efficiency of DefaultedMap.get
[ https://issues.apache.org/jira/browse/COLLECTIONS-602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16019576#comment-16019576 ] John Mark commented on COLLECTIONS-602: --- Yes, that is what I was looking for, thanks. I am attaching a patch to this ticket. > Improve efficiency of DefaultedMap.get > -- > > Key: COLLECTIONS-602 > URL: https://issues.apache.org/jira/browse/COLLECTIONS-602 > Project: Commons Collections > Issue Type: Bug >Reporter: John Mark > Labels: help-wanted > Attachments: COLLECTIONS-602.patch > > > The current implementation of > {{org.apache.commons.collections4.map.DefaultedMap.get()}} is inefficient > since it always require two map lookups. There is no need to check > map.containsKey() every time. I would suggest implementing this method > similar to the way that Java 8 does with {{Map.getOrDefault()}}. My proposed > implementation would be something like this: > {code} > public V get(final Object key) { > V v; > return ((v = map.get(key) != null) || map.containsKey(key)) ? v : > value.transform((K) key); > } > {code} > It can be further optimized to not even call map.containsKey() if map is > known to not contain null values. -- This message was sent by Atlassian JIRA (v6.3.15#6346)
[jira] [Commented] (COLLECTIONS-602) Improve efficiency of DefaultedMap.get
[ https://issues.apache.org/jira/browse/COLLECTIONS-602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16018694#comment-16018694 ] Bruno P. Kinoshita commented on COLLECTIONS-602: For general information on how to contribute, see [this page|https://commons.apache.org/patches.html]. Commons Collections is still using Subversion for code management, this is the repository https://svn.apache.org/repos/asf/commons/proper/collections/trunk If you are comfortable with Subversion, you can check out that repository, make your changes, and follow the information in the first link to create a JIRA ticket, and a patch to attach to the ticket with your changes. If you are more comfortable or prefer to use Git, you can fork https://github.com/apache/commons-collections, make all the changes in your own forked repository, and then [submit a pull request|https://help.github.com/articles/about-pull-requests/]. A committer will review your patch or pull request, and either ask for feedback or changes, and then merge it (-: Hope that helps Bruno > Improve efficiency of DefaultedMap.get > -- > > Key: COLLECTIONS-602 > URL: https://issues.apache.org/jira/browse/COLLECTIONS-602 > Project: Commons Collections > Issue Type: Bug >Reporter: John Mark > Labels: help-wanted > > The current implementation of > {{org.apache.commons.collections4.map.DefaultedMap.get()}} is inefficient > since it always require two map lookups. There is no need to check > map.containsKey() every time. I would suggest implementing this method > similar to the way that Java 8 does with {{Map.getOrDefault()}}. My proposed > implementation would be something like this: > {code} > public V get(final Object key) { > V v; > return ((v = map.get(key) != null) || map.containsKey(key)) ? v : > value.transform((K) key); > } > {code} > It can be further optimized to not even call map.containsKey() if map is > known to not contain null values. -- This message was sent by Atlassian JIRA (v6.3.15#6346)
[jira] [Commented] (COLLECTIONS-602) Improve efficiency of DefaultedMap.get
[ https://issues.apache.org/jira/browse/COLLECTIONS-602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16018672#comment-16018672 ] John Mark commented on COLLECTIONS-602: --- Sure, just let me know what the process for that is. > Improve efficiency of DefaultedMap.get > -- > > Key: COLLECTIONS-602 > URL: https://issues.apache.org/jira/browse/COLLECTIONS-602 > Project: Commons Collections > Issue Type: Bug >Reporter: John Mark > Labels: help-wanted > > The current implementation of > {{org.apache.commons.collections4.map.DefaultedMap.get()}} is inefficient > since it always require two map lookups. There is no need to check > map.containsKey() every time. I would suggest implementing this method > similar to the way that Java 8 does with {{Map.getOrDefault()}}. My proposed > implementation would be something like this: > {code} > public V get(final Object key) { > V v; > return ((v = map.get(key) != null) || map.containsKey(key)) ? v : > value.transform((K) key); > } > {code} > It can be further optimized to not even call map.containsKey() if map is > known to not contain null values. -- This message was sent by Atlassian JIRA (v6.3.15#6346)
[jira] [Commented] (COLLECTIONS-602) Improve efficiency of DefaultedMap.get
[ https://issues.apache.org/jira/browse/COLLECTIONS-602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16018175#comment-16018175 ] Bruno P. Kinoshita commented on COLLECTIONS-602: Sounds like a good argument [~jmark]. Would you be interested in submitting a pull request? :-) > Improve efficiency of DefaultedMap.get > -- > > Key: COLLECTIONS-602 > URL: https://issues.apache.org/jira/browse/COLLECTIONS-602 > Project: Commons Collections > Issue Type: Bug >Reporter: John Mark > Labels: help-wanted > > The current implementation of > {{org.apache.commons.collections4.map.DefaultedMap.get()}} is inefficient > since it always require two map lookups. There is no need to check > map.containsKey() every time. I would suggest implementing this method > similar to the way that Java 8 does with {{Map.getOrDefault()}}. My proposed > implementation would be something like this: > {code} > public V get(final Object key) { > V v; > return ((v = map.get(key) != null) || map.containsKey(key)) ? v : > value.transform((K) key); > } > {code} > It can be further optimized to not even call map.containsKey() if map is > known to not contain null values. -- This message was sent by Atlassian JIRA (v6.3.15#6346)