Skip to content

Commit

Permalink
Remove unnecessary copy of bytes. resolve apache#1085 (apache#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
kezhenxu94 authored and nick-tan committed Jul 12, 2019
1 parent 824fbec commit 876781f
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ protected void encode(ChannelHandlerContext ctx, RpcMessage msg, ByteBuf out) th
byteBuffer.putShort((short)0);
byteBuffer.putLong(msg.getId());
byteBuffer.flip();
byte[] content = new byte[byteBuffer.limit()];
byteBuffer.get(content);
out.writeBytes(content);
out.writeBytes(byteBuffer);
return;
}

Expand All @@ -89,9 +87,7 @@ protected void encode(ChannelHandlerContext ctx, RpcMessage msg, ByteBuf out) th
byteBuffer.putLong(msg.getId());

byteBuffer.flip();
byte[] content = new byte[byteBuffer.limit()];
byteBuffer.get(content);
out.writeBytes(content);
out.writeBytes(byteBuffer);
out.writeBytes(msgCodec.encode());
} else {
if (LOGGER.isInfoEnabled()) {
Expand All @@ -103,9 +99,7 @@ protected void encode(ChannelHandlerContext ctx, RpcMessage msg, ByteBuf out) th
byteBuffer.put(body);

byteBuffer.flip();
byte[] content = new byte[byteBuffer.limit()];
byteBuffer.get(content);
out.writeBytes(content);
out.writeBytes(byteBuffer);
}
} catch (Exception e) {
LOGGER.error(msg.getBody() + " encode error", "", e);
Expand Down

0 comments on commit 876781f

Please sign in to comment.