From 00c86cc8e9b5172372571cc122ebeb6d5a7e5e93 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Thu, 16 Feb 2017 16:55:56 +0200 Subject: [PATCH] buffer: remove Uint8Array check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes write[U]Int* operations on Buffer with `noAssert=false` about 3 times faster. PR-URL: https://github.com/nodejs/node/pull/11324 Refs: https://github.com/nodejs/node/issues/11245 Reviewed-By: Anna Henningsen Reviewed-By: Joyee Cheung Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso Reviewed-By: Trevor Norris --- lib/buffer.js | 2 -- test/parallel/test-buffer-write-noassert.js | 8 ++------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index dbec9bd9207b28..b6928c18f8ded3 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -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) diff --git a/test/parallel/test-buffer-write-noassert.js b/test/parallel/test-buffer-write-noassert.js index ea5ca923f01983..7423e462ca1af2 100644 --- a/test/parallel/test-buffer-write-noassert.js +++ b/test/parallel/test-buffer-write-noassert.js @@ -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$/ ); }