allocUnsafe for faster buffer cloning

It's safe to do this because we immediately overwrite the entire buffer. No need to zero out first.
This commit is contained in:
Luke Childs 2020-04-28 19:58:05 +07:00
parent 0c52803ba1
commit d02483473b
2 changed files with 2 additions and 2 deletions

View file

@ -42,7 +42,7 @@ function reverseBuffer(buffer) {
}
exports.reverseBuffer = reverseBuffer;
function cloneBuffer(buffer) {
const clone = Buffer.alloc(buffer.length);
const clone = Buffer.allocUnsafe(buffer.length);
buffer.copy(clone);
return clone;
}

View file

@ -49,7 +49,7 @@ export function reverseBuffer(buffer: Buffer): Buffer {
}
export function cloneBuffer(buffer: Buffer): Buffer {
const clone = Buffer.alloc(buffer.length);
const clone = Buffer.allocUnsafe(buffer.length);
buffer.copy(clone);
return clone;
}