mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 22:47:41 +02:00
Avoid potential packet allocation in CachedPacket#packet
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
9542de784b
commit
bef4fe37b3
@ -54,6 +54,9 @@ public final class CachedPacket implements SendablePacket {
|
|||||||
* but {@link #retrieve()} should be privileged otherwise.
|
* but {@link #retrieve()} should be privileged otherwise.
|
||||||
*/
|
*/
|
||||||
public @NotNull ServerPacket packet() {
|
public @NotNull ServerPacket packet() {
|
||||||
|
FramedPacket cache;
|
||||||
|
if (updated == 1 && (cache = packet.get()) != null)
|
||||||
|
return cache.packet(); // Avoid potential packet allocation
|
||||||
return packetSupplier.get();
|
return packetSupplier.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import java.nio.ByteBuffer;
|
|||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public record FramedPacket(@NotNull ServerPacket packet,
|
public record FramedPacket(@NotNull ServerPacket packet,
|
||||||
@NotNull ByteBuffer body) implements SendablePacket {
|
@NotNull ByteBuffer body) implements SendablePacket {
|
||||||
|
|
||||||
public FramedPacket {
|
public FramedPacket {
|
||||||
body = body.position(0).asReadOnlyBuffer();
|
body = body.position(0).asReadOnlyBuffer();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user