Improve iteration over subnets map by using entrySet instead of keyset. 55/3755/1
authorAlissa Bonas <abonas@redhat.com>
Mon, 16 Dec 2013 14:41:28 +0000 (16:41 +0200)
committerAlissa Bonas <abonas@redhat.com>
Mon, 16 Dec 2013 14:41:28 +0000 (16:41 +0200)
It is more efficient to iterate  on the entrySet because
it avoids the Map.get(key) lookup.

Change-Id: I8ec04ebfe5b22b67a488b81987f0d1f8bd1e107d
Signed-off-by: Alissa Bonas <abonas@redhat.com>
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java

index 41c783618dfdee88cadd88e2cc6d84b8e6dd05ea..f895ca0c85bd4583405453d65fcd4195dcb8b5ce 100644 (file)
@@ -691,12 +691,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
             return DEFAULT_SUBNET;
         }
 
-        Subnet sub;
-        Set<InetAddress> indices = subnets.keySet();
-        for (InetAddress i : indices) {
-            sub = subnets.get(i);
-            if (sub.isSubnetOf(networkAddress)) {
-                return sub;
+        for(Map.Entry<InetAddress,Subnet> subnetEntry : subnets.entrySet()) {
+            if(subnetEntry.getValue().isSubnetOf(networkAddress)) {
+                return subnetEntry.getValue();
             }
         }
         return null;