mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +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 Object bufferLock = new Object();
|
||||||
private final List<BinaryBuffer> waitingBuffers = new ArrayList<>();
|
private final List<BinaryBuffer> waitingBuffers = new ArrayList<>();
|
||||||
private BinaryBuffer tickBuffer = BinaryBuffer.ofSize(BUFFER_SIZE);
|
private BinaryBuffer tickBuffer = getPooledBuffer();
|
||||||
private volatile BinaryBuffer cacheBuffer;
|
private volatile BinaryBuffer cacheBuffer;
|
||||||
|
|
||||||
public PlayerSocketConnection(@NotNull Worker worker, @NotNull SocketChannel channel, SocketAddress remoteAddress) {
|
public PlayerSocketConnection(@NotNull Worker worker, @NotNull SocketChannel channel, SocketAddress remoteAddress) {
|
||||||
@ -289,10 +289,7 @@ public class PlayerSocketConnection extends PlayerConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Update tick buffer
|
// Update tick buffer
|
||||||
BinaryBuffer newBuffer = POOLED_BUFFERS.poll();
|
this.tickBuffer = getPooledBuffer();
|
||||||
if (newBuffer == null) newBuffer = BinaryBuffer.ofSize(BUFFER_SIZE);
|
|
||||||
newBuffer.clear();
|
|
||||||
this.tickBuffer = newBuffer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,4 +450,14 @@ public class PlayerSocketConnection extends PlayerConnection {
|
|||||||
public void setNonce(byte[] nonce) {
|
public void setNonce(byte[] nonce) {
|
||||||
this.nonce = 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