mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 21:17:53 +01:00
Pool main connection buffer
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
d4e51f562c
commit
3d5ae6fe94
@ -75,7 +75,7 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
|
||||
private final Object bufferLock = new Object();
|
||||
private final List<BinaryBuffer> waitingBuffers = new ArrayList<>();
|
||||
private BinaryBuffer tickBuffer = BinaryBuffer.ofSize(BUFFER_SIZE);
|
||||
private BinaryBuffer tickBuffer = getPooledBuffer();
|
||||
private volatile BinaryBuffer cacheBuffer;
|
||||
|
||||
public PlayerSocketConnection(@NotNull Worker worker, @NotNull SocketChannel channel, SocketAddress remoteAddress) {
|
||||
@ -289,10 +289,7 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
}
|
||||
}
|
||||
// Update tick buffer
|
||||
BinaryBuffer newBuffer = POOLED_BUFFERS.poll();
|
||||
if (newBuffer == null) newBuffer = BinaryBuffer.ofSize(BUFFER_SIZE);
|
||||
newBuffer.clear();
|
||||
this.tickBuffer = newBuffer;
|
||||
this.tickBuffer = getPooledBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
@ -453,4 +450,14 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
public void setNonce(byte[] nonce) {
|
||||
this.nonce = nonce;
|
||||
}
|
||||
|
||||
private static BinaryBuffer getPooledBuffer() {
|
||||
BinaryBuffer newBuffer = POOLED_BUFFERS.poll();
|
||||
if (newBuffer == null) {
|
||||
newBuffer = BinaryBuffer.ofSize(BUFFER_SIZE);
|
||||
} else {
|
||||
newBuffer.clear();
|
||||
}
|
||||
return newBuffer;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user