Improve withdrawn routes parsing 59/96959/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 20 Jul 2021 15:46:06 +0000 (17:46 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 20 Jul 2021 17:18:26 +0000 (19:18 +0200)
We are using readBytes() and release() to synchronously process a
buffer. Use readSlice(), which side-steps refcount manipulation,
making things a tad faster.

Change-Id: I89886868a2f45988620c6b8be8fb5a85c9df4ced
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 9f7749164374cef875969cd423912e0896b9d2cc)

bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java

index b2cc2f97d044a589cc549ac6e649f396d2a5686f..b0895800fe185c210d3d73abf4bbb6463639d1cd 100644 (file)
@@ -134,7 +134,7 @@ public final class BGPUpdateMessageParser implements MessageParser, MessageSeria
         final int withdrawnRoutesLength = buffer.readUnsignedShort();
         if (withdrawnRoutesLength > 0) {
             final List<WithdrawnRoutes> withdrawnRoutes = new ArrayList<>();
-            final ByteBuf withdrawnRoutesBuffer = buffer.readBytes(withdrawnRoutesLength);
+            final ByteBuf withdrawnRoutesBuffer = buffer.readSlice(withdrawnRoutesLength);
             while (withdrawnRoutesBuffer.isReadable()) {
                 final WithdrawnRoutesBuilder withdrawnRoutesBuilder = new WithdrawnRoutesBuilder();
                 if (isMultiPathSupported) {
@@ -143,7 +143,6 @@ public final class BGPUpdateMessageParser implements MessageParser, MessageSeria
                 withdrawnRoutesBuilder.setPrefix(readPrefix(withdrawnRoutesBuffer, errorHandling, "Withdrawn Routes"));
                 withdrawnRoutes.add(withdrawnRoutesBuilder.build());
             }
-            withdrawnRoutesBuffer.release();
             builder.setWithdrawnRoutes(withdrawnRoutes);
         }
         final int totalPathAttrLength = buffer.readUnsignedShort();