mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 00:17:58 +01:00
Reduce ByteBuffer allocation
This commit is contained in:
parent
f489f95bb7
commit
18058bc3c8
@ -228,12 +228,11 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
|
||||
public void write(@NotNull ByteBuffer buffer) {
|
||||
synchronized (tickBuffer) {
|
||||
buffer.flip();
|
||||
if (!tickBuffer.canWrite(buffer.limit())) {
|
||||
if (!tickBuffer.canWrite(buffer.position())) {
|
||||
// Tick buffer is full, flush before appending
|
||||
flush();
|
||||
}
|
||||
this.tickBuffer.write(buffer);
|
||||
this.tickBuffer.write(buffer.flip());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ public final class BinaryBuffer {
|
||||
}
|
||||
|
||||
public void readChannel(ReadableByteChannel channel) throws IOException {
|
||||
final int count = channel.read(asByteBuffer(readerOffset, capacity));
|
||||
final int count = channel.read(nioBuffer.position(readerOffset));
|
||||
if (count == -1) {
|
||||
// EOS
|
||||
throw new IOException("Disconnected");
|
||||
|
Loading…
Reference in New Issue
Block a user