mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-28 20:18:10 +01:00
No more memory allocation when using grouped packets
This commit is contained in:
parent
feb4783988
commit
6a9461546c
@ -9,20 +9,11 @@ public class GroupedPacketHandler extends MessageToByteEncoder<FramedPacket> {
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, FramedPacket msg, ByteBuf out) {
|
||||
final ByteBuf packet = msg.body;
|
||||
|
||||
out.setBytes(0, packet, 0, packet.writerIndex());
|
||||
out.writerIndex(packet.writerIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, FramedPacket msg, boolean preferDirect) {
|
||||
final int size = msg.body.writerIndex();
|
||||
if (preferDirect) {
|
||||
return ctx.alloc().directBuffer(size, size);
|
||||
} else {
|
||||
return ctx.alloc().heapBuffer(size, size);
|
||||
}
|
||||
return msg.body.retainedSlice();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user