Better caching for CachedPacket#packet

This commit is contained in:
themode 2022-02-25 00:01:16 +01:00
parent f09dacf795
commit d57b03f54d

View File

@ -47,12 +47,8 @@ public final class CachedPacket implements SendablePacket {
} }
public @NotNull ServerPacket packet() { public @NotNull ServerPacket packet() {
@SuppressWarnings("unchecked") FramedPacket cache = updatedCache();
SoftReference<FramedPacket> ref = (SoftReference<FramedPacket>) PACKET.getAcquire(this); return cache != null ? cache.packet() : packetSupplier.get();
FramedPacket cache;
if (ref != null && (cache = ref.get()) != null)
return cache.packet(); // Avoid potential packet allocation
return packetSupplier.get();
} }
public @NotNull ByteBuffer body() { public @NotNull ByteBuffer body() {