BUG-2825: optimize NLRI ipv4/ipv6 prefix parsing 26/35426/4
authorRobert Varga <robert.varga@pantheon.sk>
Thu, 25 Feb 2016 21:33:58 +0000 (22:33 +0100)
committerRobert Varga <rovarga@cisco.com>
Fri, 26 Feb 2016 13:42:15 +0000 (14:42 +0100)
Instead of copying arrays around, use offset-based parsers from
IetfInetUtil.

Change-Id: I2d5f8f799ae61e1d6d247827b9d0d1cee6e8b9ef
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java
util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java

index e12e580c1c9257ce3604d9120a0143cf68a49ace..781d0a969890fce9fe094a302118dd83e6084926 100644 (file)
@@ -177,9 +177,12 @@ public final class Ipv4Util {
                 list.add(EMPTY_PREFIX);
                 continue;
             }
-            final int byteCount = (bitLength % Byte.SIZE != 0) ? (bitLength / Byte.SIZE) + 1 : bitLength / Byte.SIZE;
-            list.add(prefixForBytes(ByteArray.subByte(bytes, byteOffset, byteCount), bitLength));
-            byteOffset += byteCount;
+
+            list.add(IetfInetUtil.INSTANCE.ipv4PrefixForShort(bytes, byteOffset, bitLength));
+            byteOffset += bitLength / Byte.SIZE;
+            if (bitLength % Byte.SIZE != 0) {
+                byteOffset++;
+            }
 
         }
         return list;
index ac5085f257919c750c571b94bbf7a0c4888f476f..effad46d4e19dbcff2b2f3edc61912228066cbcd 100644 (file)
@@ -154,10 +154,11 @@ public final class Ipv6Util {
                 list.add(EMPTY_PREFIX);
                 continue;
             }
-            final int byteCount = (bitLength % Byte.SIZE != 0) ? (bitLength / Byte.SIZE) + 1 : bitLength / Byte.SIZE;
-            list.add(prefixForBytes(ByteArray.subByte(bytes, byteOffset, byteCount), bitLength));
-            byteOffset += byteCount;
-
+            list.add(IetfInetUtil.INSTANCE.ipv6PrefixForShort(bytes, byteOffset, bitLength));
+            byteOffset += bitLength / Byte.SIZE;
+            if (bitLength % Byte.SIZE != 0) {
+                byteOffset++;
+            }
         }
         return list;
     }