Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
allocUnsafe for faster buffer cloning
Browse files Browse the repository at this point in the history
It's safe to do this because we immediately overwrite the entire buffer. No need to zero out first.
  • Loading branch information
lukechilds committed Apr 28, 2020
1 parent 0c52803 commit d024834
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/bufferutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion ts_src/bufferutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d024834

Please sign in to comment.