From 3cc6344c8b8e8e4baf723c8399a901f6d891ac13 Mon Sep 17 00:00:00 2001 From: Simeon Morgan Date: Tue, 12 Nov 2013 13:31:30 +1100 Subject: [PATCH] Optimised use of buffers when decrypting to avoid unnecessary array copying --- .../securesms/crypto/DecryptingPartInputStream.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java b/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java index 5c6a4d72c2..55549a298b 100644 --- a/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java +++ b/src/org/thoughtcrime/securesms/crypto/DecryptingPartInputStream.java @@ -156,6 +156,12 @@ public class DecryptingPartInputStream extends FileInputStream { //data retrieved using cipher.update doesn't always match cipher.getOutputSize (but should never be larger) int outputLen = cipher.getOutputSize(read); + + if (outputLen < length) { + readLength += cipher.update(internalBuffer, 0, read, buffer, offset); + return readLength; + } + byte[] transientBuffer = new byte[outputLen]; outputLen = cipher.update(internalBuffer, 0, read, transientBuffer, 0); if (outputLen <= length) {