Do not copy bytes when deserializing 55/111655/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 May 2024 03:01:56 +0000 (05:01 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 8 May 2024 16:21:56 +0000 (16:21 +0000)
ByteBufUtil.getBytes() performs a deep copy of the contents of the
buffer. This is completely superfluous, as we can use the underlying
nioBuffer() directly.

JIRA: CONTROLLER-2115
Change-Id: I0a9f0ec7b22682cd41063db93921c159ba66b082
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSerdes.java

index ffdc9858271ba9d79ec598e5128d7cfea15e1aad..9d6d6ee9927b817f56f528725692a4c2e4a28044 100644 (file)
@@ -20,7 +20,6 @@ import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
 import io.atomix.utils.serializer.KryoJournalSerdesBuilder;
 import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.Unpooled;
 import java.io.IOException;
 import java.io.InputStream;
@@ -127,8 +126,7 @@ public interface JournalSerdes {
 
             @Override
             public T bytesToObject(final ByteBuf buf) {
-                // FIXME: ByteBufUtil creates a copy -- we do not want to do that!
-                return deserialize(ByteBufUtil.getBytes(buf));
+                return deserialize(buf.nioBuffer());
             }
         };
     }