Skip to content

Commit

Permalink
buffer: remove Uint8Array check
Browse files Browse the repository at this point in the history
This makes write[U]Int* operations on Buffer with `noAssert=false` about 3
times faster.

PR-URL: nodejs#11324
Refs: nodejs#11245
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
seishun authored Feb 16, 2017
1 parent bd07c8f commit 00c86cc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
2 changes: 0 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,6 @@ Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {


function checkInt(buffer, value, offset, ext, max, min) {
if (!isUint8Array(buffer))
throw new TypeError('"buffer" argument must be a Buffer or Uint8Array');
if (value > max || value < min)
throw new TypeError('"value" argument is out of bounds');
if (offset + ext > buffer.length)
Expand Down
8 changes: 2 additions & 6 deletions test/parallel/test-buffer-write-noassert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ function write(funx, args, result, res) {
);
}

{
const error = /Int/.test(funx) ?
/^TypeError: "buffer" argument must be a Buffer or Uint8Array$/ :
/^TypeError: argument should be a Buffer$/;

if (!/Int/.test(funx)) {
assert.throws(
() => Buffer.alloc(9)[funx].apply(new Uint32Array(1), args),
error
/^TypeError: argument should be a Buffer$/
);
}

Expand Down

0 comments on commit 00c86cc

Please sign in to comment.