mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 13:08:19 +01:00
Avoid slice allocation
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
d21414c146
commit
885be567fa
@ -237,14 +237,16 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
if (!tickBuffer.canWrite(size)) flush();
|
||||
this.tickBuffer.write(buffer.flip());
|
||||
} else {
|
||||
final int positionCache = buffer.position();
|
||||
final int limitCache = buffer.limit();
|
||||
final int bufferCount = size / BUFFER_SIZE + 1;
|
||||
for (int i = 0; i < bufferCount; i++) {
|
||||
ByteBuffer slice = buffer.position(i * BUFFER_SIZE).slice();
|
||||
slice.limit(Math.min(slice.remaining(), BUFFER_SIZE));
|
||||
if (!tickBuffer.canWrite(slice.remaining())) flush();
|
||||
this.tickBuffer.write(slice);
|
||||
buffer.position(i * BUFFER_SIZE);
|
||||
buffer.limit(Math.min(size, buffer.position() + BUFFER_SIZE));
|
||||
if (!tickBuffer.canWrite(buffer.remaining())) flush();
|
||||
this.tickBuffer.write(buffer);
|
||||
}
|
||||
buffer.position(size);
|
||||
buffer.position(positionCache).limit(limitCache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user