Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-27 08:30:18 +01:00
Do some minor natives housekeeping.
Dieser Commit ist enthalten in:
Ursprung
55f9509c6e
Commit
a7654af1a3
@ -26,20 +26,6 @@ class CompressorUtils {
|
|||||||
*/
|
*/
|
||||||
static final int ZLIB_BUFFER_SIZE = 8192;
|
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() {
|
private CompressorUtils() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
@ -52,18 +52,13 @@ public class MoreByteBufUtils {
|
|||||||
|
|
||||||
private static boolean isCompatible(Native nativeStuff, ByteBuf buf) {
|
private static boolean isCompatible(Native nativeStuff, ByteBuf buf) {
|
||||||
BufferPreference preferred = nativeStuff.preferredBufferType();
|
BufferPreference preferred = nativeStuff.preferredBufferType();
|
||||||
switch (preferred) {
|
return switch (preferred) {
|
||||||
case DIRECT_PREFERRED:
|
case DIRECT_PREFERRED, HEAP_PREFERRED ->
|
||||||
case HEAP_PREFERRED:
|
|
||||||
// The native prefers this type, but doesn't strictly require we provide it.
|
// The native prefers this type, but doesn't strictly require we provide it.
|
||||||
return true;
|
true;
|
||||||
case DIRECT_REQUIRED:
|
case DIRECT_REQUIRED -> buf.hasMemoryAddress();
|
||||||
return buf.hasMemoryAddress();
|
case HEAP_REQUIRED -> buf.hasArray();
|
||||||
case HEAP_REQUIRED:
|
};
|
||||||
return buf.hasArray();
|
|
||||||
default:
|
|
||||||
throw new AssertionError("Preferred buffer type unknown");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,15 +72,9 @@ public class MoreByteBufUtils {
|
|||||||
*/
|
*/
|
||||||
public static ByteBuf preferredBuffer(ByteBufAllocator alloc, Native nativeStuff,
|
public static ByteBuf preferredBuffer(ByteBufAllocator alloc, Native nativeStuff,
|
||||||
int initialCapacity) {
|
int initialCapacity) {
|
||||||
switch (nativeStuff.preferredBufferType()) {
|
return switch (nativeStuff.preferredBufferType()) {
|
||||||
case HEAP_REQUIRED:
|
case HEAP_REQUIRED, HEAP_PREFERRED -> alloc.heapBuffer(initialCapacity);
|
||||||
case HEAP_PREFERRED:
|
case DIRECT_PREFERRED, DIRECT_REQUIRED -> alloc.directBuffer(initialCapacity);
|
||||||
return alloc.heapBuffer(initialCapacity);
|
};
|
||||||
case DIRECT_PREFERRED:
|
|
||||||
case DIRECT_REQUIRED:
|
|
||||||
return alloc.directBuffer(initialCapacity);
|
|
||||||
default:
|
|
||||||
throw new AssertionError("Preferred buffer type unknown");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,6 @@ public class NativeConstraints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String osArch = System.getProperty("os.arch", "");
|
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_AMD64 = osArch.equals("amd64") || osArch.equals("x86_64");
|
||||||
IS_AARCH64 = osArch.equals("aarch64") || osArch.equals("arm64");
|
IS_AARCH64 = osArch.equals("aarch64") || osArch.equals("arm64");
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren