mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-28 12:07:42 +01:00
Avoid slice allocation when compressing packets
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
d919e1b60d
commit
b18df47feb
@ -199,15 +199,12 @@ public final class PacketUtils {
|
||||
final int packetSize = buffer.position() - contentStart;
|
||||
final boolean compressed = packetSize >= MinecraftServer.getCompressionThreshold();
|
||||
if (compressed) {
|
||||
// Packet large enough, compress
|
||||
buffer.position(contentStart);
|
||||
final ByteBuffer uncompressedContent = buffer.slice().limit(packetSize);
|
||||
final ByteBuffer uncompressedCopy = localBuffer().put(uncompressedContent).flip();
|
||||
|
||||
// Packet large enough, compress it
|
||||
final ByteBuffer input = localBuffer().put(0, buffer, contentStart, packetSize);
|
||||
Deflater deflater = LOCAL_DEFLATER.get();
|
||||
deflater.setInput(uncompressedCopy);
|
||||
deflater.setInput(input.limit(packetSize));
|
||||
deflater.finish();
|
||||
deflater.deflate(buffer);
|
||||
deflater.deflate(buffer.position(contentStart));
|
||||
deflater.reset();
|
||||
}
|
||||
// Packet header (Packet + Data Length)
|
||||
|
Loading…
Reference in New Issue
Block a user