Skip to content

Commit

Permalink
Reduce byte[] creation during token validation
Browse files Browse the repository at this point in the history
Motivation:

We can just only call getAddress() once and so reduce the byte[] creation

Modifications:

Only call getAddress() once

Result:

Less garbage / memory copies during validation
  • Loading branch information
normanmaurer committed Nov 9, 2020
1 parent 528aad7 commit c97dbf0
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ public void writeToken(ByteBuf out, ByteBuf dcid, InetSocketAddress address) {

@Override
public int validateToken(ByteBuf token, InetSocketAddress address) {
final byte[] addr = address.getAddress().getAddress();

int minLength = SERVER_NAME_BYTES.length + address.getAddress().getAddress().length;
if (token.readableBytes() <= SERVER_NAME_BYTES.length + address.getAddress().getAddress().length) {
if (token.readableBytes() <= SERVER_NAME_BYTES.length + addr.length) {
return -1;
}

if (!SERVER_NAME_BUFFER.equals(token.slice(0, SERVER_NAME_BYTES.length))) {
return -1;
}
final byte[] addr = address.getAddress().getAddress();
ByteBuf addressBuffer = Unpooled.wrappedBuffer(addr);
try {
if (!addressBuffer.equals(token.slice(SERVER_NAME_BYTES.length, addr.length))) {
Expand Down

0 comments on commit c97dbf0

Please sign in to comment.