diff options
author | 2023-01-04 03:30:15 -0800 | |
---|---|---|
committer | 2023-01-04 03:30:15 -0800 | |
commit | 4a328609b96609dbeb8dc98e19aa2f52d2e5eaab (patch) | |
tree | 36d16a77ab44f3b324e3508b6a3e9f4daecf9df2 /src/bun.js/builtins/js/JSBufferConstructor.js | |
parent | 021331f154123f9fb39ac47d5c98f5a9e1095ea4 (diff) | |
download | bun-4a328609b96609dbeb8dc98e19aa2f52d2e5eaab.tar.gz bun-4a328609b96609dbeb8dc98e19aa2f52d2e5eaab.tar.zst bun-4a328609b96609dbeb8dc98e19aa2f52d2e5eaab.zip |
10x faster `new Buffer` (#1717)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/builtins/js/JSBufferConstructor.js')
-rw-r--r-- | src/bun.js/builtins/js/JSBufferConstructor.js | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/bun.js/builtins/js/JSBufferConstructor.js b/src/bun.js/builtins/js/JSBufferConstructor.js index bfb122034..48342fe26 100644 --- a/src/bun.js/builtins/js/JSBufferConstructor.js +++ b/src/bun.js/builtins/js/JSBufferConstructor.js @@ -25,6 +25,14 @@ // ^ that comment is required or the builtins generator will have a fit. +function alloc(n) { + "use strict"; + if (typeof n !== "number" || n < 0) { + @throwRangeError("n must be a positive integer less than 2^32"); + } + + return new this(n); +} function from(items) { "use strict"; @@ -64,5 +72,5 @@ function from(items) { // Don't pass the second argument because Node's Buffer.from doesn't accept // a function and Uint8Array.from requires it if it exists // That means we cannot use @tailCallFowrardArguments here, sadly - return this.toBuffer(@Uint8Array.from(arrayLike)); + return new this(@Uint8Array.from(arrayLike).buffer); } |