Remove unnecessary allocation during encryption

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-09 23:15:57 +02:00
parent 344003f36a
commit 526108b896
2 changed files with 4 additions and 6 deletions

View File

@ -279,16 +279,15 @@ public class PlayerSocketConnection extends PlayerConnection {
if (encrypted) {
final Cipher cipher = encryptCipher;
// Encrypt data first
final int remainingBytes = localBuffer.readableBytes();
final byte[] bytes = localBuffer.readRemainingBytes();
byte[] outTempArray = new byte[cipher.getOutputSize(remainingBytes)];
ByteBuffer cipherInput = localBuffer.asByteBuffer(0, localBuffer.writerOffset());
ByteBuffer cipherOutput = getPooledBuffer().asByteBuffer(0, BUFFER_SIZE);
try {
cipher.update(bytes, 0, remainingBytes, outTempArray);
cipher.update(cipherInput, cipherOutput);
} catch (ShortBufferException e) {
MinecraftServer.getExceptionManager().handleException(e);
}
localBuffer.clear();
localBuffer.writeBytes(outTempArray);
localBuffer.write(cipherOutput.flip());
}
this.waitingBuffers.add(localBuffer);

View File

@ -14,7 +14,6 @@ import java.util.function.Consumer;
public final class EntityUtils {
private EntityUtils() {
}
public static void forEachRange(@NotNull Instance instance, @NotNull Point point,