From a7654af1a3c5885c96769a05d43a5604dc47de10 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 2 Sep 2024 02:57:03 -0400 Subject: [PATCH] Do some minor natives housekeeping. --- .../natives/compression/CompressorUtils.java | 14 --------- .../natives/util/MoreByteBufUtils.java | 31 ++++++------------- .../natives/util/NativeConstraints.java | 2 -- 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/native/src/main/java/com/velocitypowered/natives/compression/CompressorUtils.java b/native/src/main/java/com/velocitypowered/natives/compression/CompressorUtils.java index 8230ba204..94cde4bd5 100644 --- a/native/src/main/java/com/velocitypowered/natives/compression/CompressorUtils.java +++ b/native/src/main/java/com/velocitypowered/natives/compression/CompressorUtils.java @@ -26,20 +26,6 @@ class CompressorUtils { */ static final int ZLIB_BUFFER_SIZE = 8192; - /** - * Ensures that the buffer does not go over {@code max}. - * - * @param buf the buffer for check - * @param max the maximum size for the buffer - * @throws DataFormatException if the buffer becomes too bug - */ - static void ensureMaxSize(ByteBuf buf, int max) throws DataFormatException { - int len = buf.readableBytes(); - if (len > max) { - throw new DataFormatException("Got too much data (" + len + " > " + max + ")"); - } - } - private CompressorUtils() { throw new AssertionError(); } 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 fbad62bf9..13f4f0c57 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/MoreByteBufUtils.java +++ b/native/src/main/java/com/velocitypowered/natives/util/MoreByteBufUtils.java @@ -52,18 +52,13 @@ public class MoreByteBufUtils { private static boolean isCompatible(Native nativeStuff, ByteBuf buf) { BufferPreference preferred = nativeStuff.preferredBufferType(); - switch (preferred) { - case DIRECT_PREFERRED: - case HEAP_PREFERRED: + return switch (preferred) { + case DIRECT_PREFERRED, HEAP_PREFERRED -> // The native prefers this type, but doesn't strictly require we provide it. - return true; - case DIRECT_REQUIRED: - return buf.hasMemoryAddress(); - case HEAP_REQUIRED: - return buf.hasArray(); - default: - throw new AssertionError("Preferred buffer type unknown"); - } + true; + case DIRECT_REQUIRED -> buf.hasMemoryAddress(); + case HEAP_REQUIRED -> buf.hasArray(); + }; } /** @@ -77,15 +72,9 @@ public class MoreByteBufUtils { */ public static ByteBuf preferredBuffer(ByteBufAllocator alloc, Native nativeStuff, int initialCapacity) { - switch (nativeStuff.preferredBufferType()) { - case HEAP_REQUIRED: - case HEAP_PREFERRED: - return alloc.heapBuffer(initialCapacity); - case DIRECT_PREFERRED: - case DIRECT_REQUIRED: - return alloc.directBuffer(initialCapacity); - default: - throw new AssertionError("Preferred buffer type unknown"); - } + return switch (nativeStuff.preferredBufferType()) { + case HEAP_REQUIRED, HEAP_PREFERRED -> alloc.heapBuffer(initialCapacity); + case DIRECT_PREFERRED, DIRECT_REQUIRED -> alloc.directBuffer(initialCapacity); + }; } } diff --git a/native/src/main/java/com/velocitypowered/natives/util/NativeConstraints.java b/native/src/main/java/com/velocitypowered/natives/util/NativeConstraints.java index f707ab248..04e5faff0 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/NativeConstraints.java +++ b/native/src/main/java/com/velocitypowered/natives/util/NativeConstraints.java @@ -39,8 +39,6 @@ public class NativeConstraints { } String osArch = System.getProperty("os.arch", ""); - // HotSpot on Intel macOS prefers x86_64, but OpenJ9 on macOS and HotSpot/OpenJ9 elsewhere - // give amd64. IS_AMD64 = osArch.equals("amd64") || osArch.equals("x86_64"); IS_AARCH64 = osArch.equals("aarch64") || osArch.equals("arm64"); }