Merge pull request #15539 from Snuffleupagus/DecryptStream-set

Replace loop with `TypedArray.prototype.set` in the `DecryptStream.readBlock` method
This commit is contained in:
Jonas Jenwald 2022-10-07 11:14:28 +02:00 committed by GitHub
commit 3cb119cb32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,13 +46,11 @@ class DecryptStream extends DecodeStream {
const decrypt = this.decrypt; const decrypt = this.decrypt;
chunk = decrypt(chunk, !hasMoreData); chunk = decrypt(chunk, !hasMoreData);
let bufferLength = this.bufferLength; const bufferLength = this.bufferLength,
const n = chunk.length, newLength = bufferLength + chunk.length,
buffer = this.ensureBuffer(bufferLength + n); buffer = this.ensureBuffer(newLength);
for (let i = 0; i < n; i++) { buffer.set(chunk, bufferLength);
buffer[bufferLength++] = chunk[i]; this.bufferLength = newLength;
}
this.bufferLength = bufferLength;
} }
} }