mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-08 11:50:36 +01:00
Better caching for CachedPacket#packet
This commit is contained in:
parent
f09dacf795
commit
d57b03f54d
@ -47,12 +47,8 @@ public final class CachedPacket implements SendablePacket {
|
||||
}
|
||||
|
||||
public @NotNull ServerPacket packet() {
|
||||
@SuppressWarnings("unchecked")
|
||||
SoftReference<FramedPacket> ref = (SoftReference<FramedPacket>) PACKET.getAcquire(this);
|
||||
FramedPacket cache;
|
||||
if (ref != null && (cache = ref.get()) != null)
|
||||
return cache.packet(); // Avoid potential packet allocation
|
||||
return packetSupplier.get();
|
||||
FramedPacket cache = updatedCache();
|
||||
return cache != null ? cache.packet() : packetSupplier.get();
|
||||
}
|
||||
|
||||
public @NotNull ByteBuffer body() {
|
||||
|
Loading…
Reference in New Issue
Block a user