mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 09:27: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) {
|
public void write(@NotNull ByteBuffer buffer) {
|
||||||
synchronized (tickBuffer) {
|
synchronized (tickBuffer) {
|
||||||
buffer.flip();
|
if (!tickBuffer.canWrite(buffer.position())) {
|
||||||
if (!tickBuffer.canWrite(buffer.limit())) {
|
|
||||||
// Tick buffer is full, flush before appending
|
// Tick buffer is full, flush before appending
|
||||||
flush();
|
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 {
|
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) {
|
if (count == -1) {
|
||||||
// EOS
|
// EOS
|
||||||
throw new IOException("Disconnected");
|
throw new IOException("Disconnected");
|
||||||
|
Loading…
Reference in New Issue
Block a user