428232 - Rework batch mode / buffering in websocket.
Avoid to create a new ByteBuffer just to create the mask integer, saves allocation cost.
This commit is contained in:
parent
61b4b0f029
commit
0786da6cd0
|
@ -284,7 +284,9 @@ public class Generator
|
|||
{
|
||||
byte[] mask = frame.getMask();
|
||||
buffer.put(mask);
|
||||
int maskInt = ByteBuffer.wrap(mask).getInt();
|
||||
int maskInt = 0;
|
||||
for (byte maskByte : mask)
|
||||
maskInt = (maskInt << 8) + (maskByte & 0xFF);
|
||||
|
||||
// perform data masking here
|
||||
ByteBuffer payload = frame.getPayload();
|
||||
|
|
|
@ -24,7 +24,8 @@ import org.eclipse.jetty.websocket.api.extensions.Frame;
|
|||
|
||||
public class DeMaskProcessor implements PayloadProcessor
|
||||
{
|
||||
private byte maskBytes[];
|
||||
private byte[] maskBytes;
|
||||
private int maskInt;
|
||||
private int maskOffset;
|
||||
|
||||
@Override
|
||||
|
@ -35,14 +36,14 @@ public class DeMaskProcessor implements PayloadProcessor
|
|||
return;
|
||||
}
|
||||
|
||||
int maskInt = ByteBuffer.wrap(maskBytes).getInt();
|
||||
int maskInt = this.maskInt;
|
||||
int start = payload.position();
|
||||
int end = payload.limit();
|
||||
int offset = this.maskOffset;
|
||||
int remaining;
|
||||
while ((remaining = end - start) > 0)
|
||||
{
|
||||
if (remaining >= 4 && (offset % 4) == 0)
|
||||
if (remaining >= 4 && (offset & 3) == 0)
|
||||
{
|
||||
payload.putInt(start,payload.getInt(start) ^ maskInt);
|
||||
start += 4;
|
||||
|
@ -61,6 +62,10 @@ public class DeMaskProcessor implements PayloadProcessor
|
|||
public void reset(byte mask[])
|
||||
{
|
||||
this.maskBytes = mask;
|
||||
int maskInt = 0;
|
||||
for (byte maskByte : maskBytes)
|
||||
maskInt = (maskInt << 8) + (maskByte & 0xFF);
|
||||
this.maskInt = maskInt;
|
||||
this.maskOffset = 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue