Reduce ByteBuffer allocation

This commit is contained in:
TheMode 2021-08-09 23:54:45 +02:00
parent f489f95bb7
commit 18058bc3c8
2 changed files with 3 additions and 4 deletions

View File

@ -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());
}
}

View File

@ -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");