Use ByteBuf.readSlice(...).retain() to minimize memory copies.
Motivation:
At the moment we call ByteBuf.readBytes(...) in these handlers but with optimizations done as part of 25e0d9d
we can just use readSlice(...).retain() and eliminate the memory copy.
Modifications:
Replace ByteBuf.readBytes(...) usage with readSlice(...).retain().
Result:
Less memory copies.
This commit is contained in:
parent
59d92ad6cf
commit
880acbca72
@ -268,13 +268,13 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder {
|
||||
}
|
||||
|
||||
if (stripDelimiter) {
|
||||
frame = buffer.readBytes(minFrameLength);
|
||||
frame = buffer.readSlice(minFrameLength);
|
||||
buffer.skipBytes(minDelimLength);
|
||||
} else {
|
||||
frame = buffer.readBytes(minFrameLength + minDelimLength);
|
||||
frame = buffer.readSlice(minFrameLength + minDelimLength);
|
||||
}
|
||||
|
||||
return frame;
|
||||
return frame.retain();
|
||||
} else {
|
||||
if (!discardingTooLongFrame) {
|
||||
if (buffer.readableBytes() > maxFrameLength) {
|
||||
|
@ -74,7 +74,7 @@ public class FixedLengthFrameDecoder extends ByteToMessageDecoder {
|
||||
if (in.readableBytes() < frameLength) {
|
||||
return null;
|
||||
} else {
|
||||
return in.readBytes(frameLength);
|
||||
return in.readSlice(frameLength).retain();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,13 +100,13 @@ public class LineBasedFrameDecoder extends ByteToMessageDecoder {
|
||||
}
|
||||
|
||||
if (stripDelimiter) {
|
||||
frame = buffer.readBytes(length);
|
||||
frame = buffer.readSlice(length);
|
||||
buffer.skipBytes(delimLength);
|
||||
} else {
|
||||
frame = buffer.readBytes(length + delimLength);
|
||||
frame = buffer.readSlice(length + delimLength);
|
||||
}
|
||||
|
||||
return frame;
|
||||
return frame.retain();
|
||||
} else {
|
||||
final int length = buffer.readableBytes();
|
||||
if (length > maxLength) {
|
||||
|
Loading…
Reference in New Issue
Block a user