0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

stream: avoid possible slow path w UInt8Array

A chunk validity checks verifie if a chunk is a UInt8Array.
We should defer it as it might be very expensive in older Node.js
platforms.

PR-URL: https://github.com/nodejs/node/pull/13956
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
Matteo Collina 2017-06-27 19:03:00 +02:00
parent d111319270
commit 027960205f

View File

@ -248,7 +248,7 @@ function validChunk(stream, state, chunk, cb) {
Writable.prototype.write = function(chunk, encoding, cb) {
var state = this._writableState;
var ret = false;
var isBuf = Stream._isUint8Array(chunk) && !state.objectMode;
var isBuf = !state.objectMode && Stream._isUint8Array(chunk);
if (isBuf && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
chunk = Stream._uint8ArrayToBuffer(chunk);