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:
parent
0c52803ba1
commit
d02483473b
2 changed files with 2 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue