BUG-2825: optimize NLRI ipv4/ipv6 prefix parsing 39/35939/4
authorRobert Varga <robert.varga@pantheon.sk>
Thu, 25 Feb 2016 21:33:58 +0000 (22:33 +0100)
committerRobert Varga <rovarga@cisco.com>
Wed, 9 Mar 2016 09:38:40 +0000 (10:38 +0100)
Instead of copying arrays around, use offset-based parsers from
IetfInetUtil.

Change-Id: I2d5f8f799ae61e1d6d247827b9d0d1cee6e8b9ef
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
(cherry picked from commit e7ffadf95911352e64f93d2357dffa1a7ff52741)

util/src/main/java/org/opendaylight/protocol/util/Ipv4Util.java
util/src/main/java/org/opendaylight/protocol/util/Ipv6Util.java

index dfb47a771cfc27e6ed3578c35cc56a5084e5ed5d..9fa5dc93262742dc36e965e082bb6d3683635609 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;
     }