mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 21:17:53 +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 int packetSize = buffer.position() - contentStart;
|
||||||
final boolean compressed = packetSize >= MinecraftServer.getCompressionThreshold();
|
final boolean compressed = packetSize >= MinecraftServer.getCompressionThreshold();
|
||||||
if (compressed) {
|
if (compressed) {
|
||||||
// Packet large enough, compress
|
// Packet large enough, compress it
|
||||||
buffer.position(contentStart);
|
final ByteBuffer input = localBuffer().put(0, buffer, contentStart, packetSize);
|
||||||
final ByteBuffer uncompressedContent = buffer.slice().limit(packetSize);
|
|
||||||
final ByteBuffer uncompressedCopy = localBuffer().put(uncompressedContent).flip();
|
|
||||||
|
|
||||||
Deflater deflater = LOCAL_DEFLATER.get();
|
Deflater deflater = LOCAL_DEFLATER.get();
|
||||||
deflater.setInput(uncompressedCopy);
|
deflater.setInput(input.limit(packetSize));
|
||||||
deflater.finish();
|
deflater.finish();
|
||||||
deflater.deflate(buffer);
|
deflater.deflate(buffer.position(contentStart));
|
||||||
deflater.reset();
|
deflater.reset();
|
||||||
}
|
}
|
||||||
// Packet header (Packet + Data Length)
|
// Packet header (Packet + Data Length)
|
||||||
|
Loading…
Reference in New Issue
Block a user