From 8fd6c0525d7fe36a2f94d11fe978d02a429abe12 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 27 Jun 2017 19:03:00 +0200 Subject: [PATCH] stream: avoid possible slow path w UInt8Array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Anna Henningsen Reviewed-By: Timothy Gu Reviewed-By: Michaël Zasso Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen --- lib/_stream_writable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 78ab13d9063c67..334f492ba68eef 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -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);