Skip to content

Commit

Permalink
[perf] Make toBuffer() use FastBuffer
Browse files Browse the repository at this point in the history
Skip unnecessary parameter validation performed by `Buffer.from()` when
possible.
  • Loading branch information
lpinca committed Dec 13, 2022
1 parent 1b057f9 commit 83c72cf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/buffer-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ function toBuffer(data) {
let buf;

if (data instanceof ArrayBuffer) {
buf = Buffer.from(data);
buf = new FastBuffer(data);
} else if (ArrayBuffer.isView(data)) {
buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
} else {
buf = Buffer.from(data);
toBuffer.readOnly = false;
Expand Down

0 comments on commit 83c72cf

Please sign in to comment.