mirror of https://github.com/Minestom/Minestom.git
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.
|
||||
*/
|
||||
public @NotNull ServerPacket packet() {
|
||||
FramedPacket cache;
|
||||
if (updated == 1 && (cache = packet.get()) != null)
|
||||
return cache.packet(); // Avoid potential packet allocation
|
||||
return packetSupplier.get();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.nio.ByteBuffer;
|
|||
@ApiStatus.Internal
|
||||
public record FramedPacket(@NotNull ServerPacket packet,
|
||||
@NotNull ByteBuffer body) implements SendablePacket {
|
||||
|
||||
public FramedPacket {
|
||||
body = body.position(0).asReadOnlyBuffer();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue