From da80e9034c2242954c56d7e56a7fc407ffe99fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Andr=C3=A9=20Pearce?= Date: Wed, 10 May 2017 02:33:37 +0100 Subject: [PATCH] Avoid byte[] copy Avoid copying bytes, instead simply slice the existing buffer. This avoids if the buffer is off heap, it becoming on heap. --- .../artemis/core/protocol/core/impl/PacketImpl.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/PacketImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/PacketImpl.java index 97a7973f7af..e5d23d05e0c 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/PacketImpl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/PacketImpl.java @@ -347,18 +347,7 @@ public void decode(final ActiveMQBuffer buffer) { } protected ByteBuf copyMessageBuffer(ByteBuf buffer, int skipBytes) { - - ByteBuf newNettyBuffer = Unpooled.buffer(buffer.capacity() - PACKET_HEADERS_SIZE - skipBytes); - - int read = buffer.readerIndex(); - int writ = buffer.writerIndex(); - buffer.readerIndex(PACKET_HEADERS_SIZE); - - newNettyBuffer.writeBytes(buffer, buffer.readableBytes() - skipBytes); - buffer.setIndex( read, writ ); - newNettyBuffer.setIndex( 0, writ - PACKET_HEADERS_SIZE - skipBytes); - - return newNettyBuffer; + return buffer.retainedSlice(PACKET_HEADERS_SIZE, buffer.readableBytes() - skipBytes); }