From 821a7a45bce17d008bfcc2afc479388e4da80129 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 21 May 2019 00:56:14 -0400 Subject: [PATCH] Small optimization for NativeVelocityCipher Instead of going through the general process function, which does extra checks to ensure that its arguments are sane, move "closer" to the action by stripping down to the actual implementation. --- .../encryption/NativeVelocityCipher.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/native/src/main/java/com/velocitypowered/natives/encryption/NativeVelocityCipher.java b/native/src/main/java/com/velocitypowered/natives/encryption/NativeVelocityCipher.java index 56905c085..a9a0267f3 100644 --- a/native/src/main/java/com/velocitypowered/natives/encryption/NativeVelocityCipher.java +++ b/native/src/main/java/com/velocitypowered/natives/encryption/NativeVelocityCipher.java @@ -50,14 +50,16 @@ public class NativeVelocityCipher implements VelocityCipher { @Override public ByteBuf process(ChannelHandlerContext ctx, ByteBuf source) throws ShortBufferException { - ByteBuf out = ctx.alloc().directBuffer(source.readableBytes()); - try { - process(source, out); - return out; - } catch (Exception e) { - out.release(); - throw e; - } + ensureNotDisposed(); + + int len = source.readableBytes(); + ByteBuf out = ctx.alloc().directBuffer(len); + + impl.process(this.ctx, source.memoryAddress() + source.readerIndex(), len, + out.memoryAddress(), encrypt); + source.skipBytes(len); + out.writerIndex(len); + return out; } @Override