From: Alissa Bonas Date: Wed, 25 Dec 2013 17:23:33 +0000 (+0200) Subject: Optimization - calculate the subnet prefix only once. X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~17^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=795acce15158be694bbc8a580ff2feda4cf0b555 Optimization - calculate the subnet prefix only once. Before this change, subnet prefix was calculated on every 'isSubnetOf' call. Since the prefix is not changing unless the subnet address itself changed, it's sufficient to do it only once and keep it as part of the Subnet object. Marked it as transient so it will not be serialized - it can be calculated from the rest of the info of Subnet anytime after deserialization. Change-Id: Ie16bf80713820b566864bea0ff46298c93cc2d47 Signed-off-by: Alissa Bonas --- diff --git a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Subnet.java b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Subnet.java index 56df8e26bd..2794109c24 100644 --- a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Subnet.java +++ b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Subnet.java @@ -25,6 +25,7 @@ public class Subnet implements Cloneable, Serializable { private static final long serialVersionUID = 1L; // Key fields private InetAddress networkAddress; + private transient InetAddress subnetPrefix; private short subnetMaskLength; // Property fields private short vlan; @@ -114,6 +115,7 @@ public class Subnet implements Cloneable, Serializable { */ public Subnet setNetworkAddress(InetAddress networkAddress) { this.networkAddress = networkAddress; + this.subnetPrefix = null; return this; } @@ -159,10 +161,12 @@ public class Subnet implements Cloneable, Serializable { if (ip == null) { return false; } - InetAddress thisPrefix = getPrefixForAddress(this.networkAddress); + if(subnetPrefix == null) { + subnetPrefix = getPrefixForAddress(this.networkAddress); + } InetAddress otherPrefix = getPrefixForAddress(ip); boolean isSubnetOf = true; - if (((thisPrefix == null) || (otherPrefix == null)) || (!thisPrefix.equals(otherPrefix)) ) { + if (((subnetPrefix == null) || (otherPrefix == null)) || (!subnetPrefix.equals(otherPrefix)) ) { isSubnetOf = false; } return isSubnetOf;