From 25773cd366360e2c4c4ffd99cd876b3317403fe6 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 30 Dec 2018 07:18:19 -0500 Subject: [PATCH] Fix typo, clarification, pre-size buffer in ensureCompatible(). --- .../com/velocitypowered/natives/util/MoreByteBufUtils.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/native/src/main/java/com/velocitypowered/natives/util/MoreByteBufUtils.java b/native/src/main/java/com/velocitypowered/natives/util/MoreByteBufUtils.java index 92c19a0c7..c91e6c942 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/MoreByteBufUtils.java +++ b/native/src/main/java/com/velocitypowered/natives/util/MoreByteBufUtils.java @@ -10,7 +10,7 @@ public class MoreByteBufUtils { } /** - * Ensures the {@code buf} will work with the specified {@code nativeThing}. After this function + * Ensures the {@code buf} will work with the specified {@code nativeStuff}. After this function * is called, you should decrement the reference count on the {@code buf} with * {@link ByteBuf#release()}. * @@ -21,12 +21,13 @@ public class MoreByteBufUtils { */ public static ByteBuf ensureCompatible(ByteBufAllocator alloc, Native nativeStuff, ByteBuf buf) { if (!nativeStuff.isNative() || buf.hasMemoryAddress()) { - // Will always work in either case. + // Will always work in either case. JNI code demands a memory address, and if we have a Java + // fallback, it uses byte arrays in all cases. return buf.retain(); } // It's not, so we must make a direct copy. - ByteBuf newBuf = alloc.directBuffer(); + ByteBuf newBuf = alloc.directBuffer(buf.readableBytes()); newBuf.writeBytes(buf); return newBuf; }