buffer: remove Uint8Array check
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 <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>
This commit is contained in:
parent
bd07c8fc12
commit
00c86cc8e9
@ -1056,8 +1056,6 @@ Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
|
|||||||
|
|
||||||
|
|
||||||
function checkInt(buffer, value, offset, ext, max, min) {
|
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)
|
if (value > max || value < min)
|
||||||
throw new TypeError('"value" argument is out of bounds');
|
throw new TypeError('"value" argument is out of bounds');
|
||||||
if (offset + ext > buffer.length)
|
if (offset + ext > buffer.length)
|
||||||
|
@ -20,14 +20,10 @@ function write(funx, args, result, res) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if (!/Int/.test(funx)) {
|
||||||
const error = /Int/.test(funx) ?
|
|
||||||
/^TypeError: "buffer" argument must be a Buffer or Uint8Array$/ :
|
|
||||||
/^TypeError: argument should be a Buffer$/;
|
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => Buffer.alloc(9)[funx].apply(new Uint32Array(1), args),
|
() => Buffer.alloc(9)[funx].apply(new Uint32Array(1), args),
|
||||||
error
|
/^TypeError: argument should be a Buffer$/
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user