mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-29 11:31:50 +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() {
|
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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user