Yuta HIGUCHI
Committed by Gerrit Code Review

Reduce number of Map lookups

Change-Id: I6ea71c120e9143dabdb44dfd86b78f570647eb4b
...@@ -26,6 +26,7 @@ import org.onosproject.net.resource.Resources; ...@@ -26,6 +26,7 @@ import org.onosproject.net.resource.Resources;
26 import java.util.LinkedHashMap; 26 import java.util.LinkedHashMap;
27 import java.util.LinkedHashSet; 27 import java.util.LinkedHashSet;
28 import java.util.Map; 28 import java.util.Map;
29 +import java.util.Map.Entry;
29 import java.util.Objects; 30 import java.util.Objects;
30 import java.util.Optional; 31 import java.util.Optional;
31 import java.util.Set; 32 import java.util.Set;
...@@ -100,13 +101,14 @@ final class EncodableDiscreteResources implements DiscreteResources { ...@@ -100,13 +101,14 @@ final class EncodableDiscreteResources implements DiscreteResources {
100 EncodableDiscreteResources cast = (EncodableDiscreteResources) other; 101 EncodableDiscreteResources cast = (EncodableDiscreteResources) other;
101 102
102 Map<Class<?>, EncodedDiscreteResources> newMap = new LinkedHashMap<>(); 103 Map<Class<?>, EncodedDiscreteResources> newMap = new LinkedHashMap<>();
103 - for (Class<?> key : this.map.keySet()) { 104 + for (Entry<Class<?>, EncodedDiscreteResources> e : this.map.entrySet()) {
104 - EncodedDiscreteResources thisValues = this.map.get(key); 105 + Class<?> key = e.getKey();
105 - if (!cast.map.containsKey(key)) { 106 + EncodedDiscreteResources thisValues = e.getValue();
107 + EncodedDiscreteResources otherValues = cast.map.get(key);
108 + if (otherValues == null) {
106 newMap.put(key, thisValues); 109 newMap.put(key, thisValues);
107 continue; 110 continue;
108 } 111 }
109 - EncodedDiscreteResources otherValues = cast.map.get(key);
110 EncodedDiscreteResources diff = thisValues.difference(otherValues); 112 EncodedDiscreteResources diff = thisValues.difference(otherValues);
111 // omit empty resources from a new resource set 113 // omit empty resources from a new resource set
112 // empty EncodedDiscreteResources can't deserialize due to 114 // empty EncodedDiscreteResources can't deserialize due to
......