mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-29 04:28:21 +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
|
@Override
|
||||||
protected void encode(ChannelHandlerContext ctx, FramedPacket msg, ByteBuf out) {
|
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
|
@Override
|
||||||
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, FramedPacket msg, boolean preferDirect) {
|
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, FramedPacket msg, boolean preferDirect) {
|
||||||
final int size = msg.body.writerIndex();
|
return msg.body.retainedSlice();
|
||||||
if (preferDirect) {
|
|
||||||
return ctx.alloc().directBuffer(size, size);
|
|
||||||
} else {
|
|
||||||
return ctx.alloc().heapBuffer(size, size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user