From 6877d8b9e29b0fff613048b53d692236a200cc58 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 6 Oct 2022 14:43:24 +0200 Subject: [PATCH] Replace loop with `TypedArray.prototype.set` in the `DecryptStream.readBlock` method There's no reason to use a manual loop, when a native method exists. --- src/core/decrypt_stream.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/decrypt_stream.js b/src/core/decrypt_stream.js index 6848ead7e..47dbd35cf 100644 --- a/src/core/decrypt_stream.js +++ b/src/core/decrypt_stream.js @@ -46,13 +46,11 @@ class DecryptStream extends DecodeStream { const decrypt = this.decrypt; chunk = decrypt(chunk, !hasMoreData); - let bufferLength = this.bufferLength; - const n = chunk.length, - buffer = this.ensureBuffer(bufferLength + n); - for (let i = 0; i < n; i++) { - buffer[bufferLength++] = chunk[i]; - } - this.bufferLength = bufferLength; + const bufferLength = this.bufferLength, + newLength = bufferLength + chunk.length, + buffer = this.ensureBuffer(newLength); + buffer.set(chunk, bufferLength); + this.bufferLength = newLength; } }