Author: kinow
Date: Wed May 24 09:32:48 2017
New Revision: 1796031

URL: http://svn.apache.org/viewvc?rev=1796031&view=rev
Log:
COLLECTIONS-602: Improve efficiency of DefaultedMap.get. Applying patch 
provided by John Mark.


Modified:
    commons/proper/collections/trunk/src/changes/changes.xml
    
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/DefaultedMap.java

Modified: commons/proper/collections/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1796031&r1=1796030&r2=1796031&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Wed May 24 
09:32:48 2017
@@ -21,6 +21,9 @@
   </properties>
   <body>
   <release version="4.2" date="YYYY-MM-DD" description="New features">
+    <action issue="COLLECTIONS-602" dev="kinow" type="update" due-to="John 
Mark">
+      Improve efficiency of DefaultedMap.get
+    </action>
     <action issue="COLLECTIONS-603" dev="kinow" type="fix" due-to="Artem 
Konovalov">
       Small improvements for generics, conditional statements, and warnings 
suppressions.
     </action>

Modified: 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/DefaultedMap.java
URL: 
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/DefaultedMap.java?rev=1796031&r1=1796030&r2=1796031&view=diff
==============================================================================
--- 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/DefaultedMap.java
 (original)
+++ 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/map/DefaultedMap.java
 Wed May 24 09:32:48 2017
@@ -198,11 +198,10 @@ public class DefaultedMap<K, V> extends
     @Override
     @SuppressWarnings("unchecked")
     public V get(final Object key) {
-        // create value for key if key is not currently in the map
-        if (map.containsKey(key) == false) {
-            return value.transform((K) key);
-        }
-        return map.get(key);
+        V v;
+        return (((v = map.get(key)) != null) || map.containsKey(key))
+          ? v
+          : value.transform((K) key);
     }
 
     // no need to wrap keySet, entrySet or values as they are views of


Reply via email to