Improve withdrawn routes parsing 52/96952/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 15:46:06 +0000 (17:46 +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>
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPUpdateMessageParser.java

index 57cd3f6b0f2c7e8dd06dd179a3591c89bd64797b..275afc80c5dc9a7aa31039028b467655c43a9451 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();