From 8f346f9f1263b2fd5923abc0956134df15fd9325 Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Wed, 24 May 2017 09:32:48 +0000 Subject: [PATCH] COLLECTIONS-602: Improve efficiency of DefaultedMap.get. Applying patch provided by John Mark. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1796031 13f79535-47bb-0310-9956-ffa450edef68 --- src/changes/changes.xml | 3 +++ .../apache/commons/collections4/map/DefaultedMap.java | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9b39615d2..bf23905f5 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -21,6 +21,9 @@ + + Improve efficiency of DefaultedMap.get + Small improvements for generics, conditional statements, and warnings suppressions. diff --git a/src/main/java/org/apache/commons/collections4/map/DefaultedMap.java b/src/main/java/org/apache/commons/collections4/map/DefaultedMap.java index 17605fd32..7c0d78371 100644 --- a/src/main/java/org/apache/commons/collections4/map/DefaultedMap.java +++ b/src/main/java/org/apache/commons/collections4/map/DefaultedMap.java @@ -198,11 +198,10 @@ public class DefaultedMap extends AbstractMapDecorator implements Se @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