mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-06 02:41:59 +01:00
Use LocalCache
for deflaters
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
9fe3f28497
commit
f07ab21d3e
@ -40,7 +40,7 @@ import java.util.zip.Deflater;
|
||||
*/
|
||||
public final class PacketUtils {
|
||||
private static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager();
|
||||
private static final ThreadLocal<Deflater> LOCAL_DEFLATER = ThreadLocal.withInitial(Deflater::new);
|
||||
private static final LocalCache<Deflater> LOCAL_DEFLATER = LocalCache.of(Deflater::new);
|
||||
|
||||
/// Local buffers
|
||||
private static final LocalCache<ByteBuffer> PACKET_BUFFER = LocalCache.ofBuffer(Server.MAX_PACKET_SIZE);
|
||||
|
@ -27,8 +27,12 @@ public final class LocalCache<T> {
|
||||
this.fallback = ThreadLocal.withInitial(supplier);
|
||||
}
|
||||
|
||||
public static <T> LocalCache<T> of(@NotNull Supplier<T> supplier) {
|
||||
return new LocalCache<>(supplier);
|
||||
}
|
||||
|
||||
public static LocalCache<ByteBuffer> ofBuffer(int size) {
|
||||
return new LocalCache<>(() -> ByteBuffer.allocateDirect(size));
|
||||
return of(() -> ByteBuffer.allocateDirect(size));
|
||||
}
|
||||
|
||||
public T get() {
|
||||
|
Loading…
Reference in New Issue
Block a user