Optimize encoding of websocket frames by merge if possible

This commit is contained in:
Norman Maurer 2013-12-13 11:39:39 +01:00
parent ee17139a03
commit 48b416f112

View File

@ -185,10 +185,16 @@ public class WebSocket08FrameEncoder extends MessageToMessageEncoder<WebSocketFr
buf.writeByte(byteData ^ mask[counter++ % 4]);
}
out.add(buf);
} else {
if (buf.writableBytes() >= data.readableBytes()) {
// merge buffers as this is cheaper then a gathering write if the payload is small enough
buf.writeBytes(data);
out.add(buf);
} else {
out.add(buf);
out.add(data.retain());
}
}
release = false;
} finally {
if (release && buf != null) {