From 72ff71e45d08274f4d61abcacc5214f91ce7ba7a Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 25 Feb 2017 22:16:57 -0800 Subject: [PATCH] stream: avoid using forEach PR-URL: https://github.com/nodejs/node/pull/11582 Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig --- lib/_stream_readable.js | 9 +++++---- lib/_stream_wrap.js | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 1f7bdcc2e7c465..5d0e8aa243e9d6 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -34,6 +34,8 @@ var StringDecoder; util.inherits(Readable, Stream); +const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume']; + function prependListener(emitter, event, fn) { // Sadly this is not cacheable as some libraries bundle their own // event emitter implementation with them. @@ -828,10 +830,9 @@ Readable.prototype.wrap = function(stream) { } // proxy certain important events. - const events = ['error', 'close', 'destroy', 'pause', 'resume']; - events.forEach(function(ev) { - stream.on(ev, self.emit.bind(self, ev)); - }); + for (var n = 0; n < kProxyEvents.length; n++) { + stream.on(kProxyEvents[n], self.emit.bind(self, kProxyEvents[n])); + } // when we try to consume some more bytes, simply unpause the // underlying stream. diff --git a/lib/_stream_wrap.js b/lib/_stream_wrap.js index fbc32965980e96..2ddf15069e5361 100644 --- a/lib/_stream_wrap.js +++ b/lib/_stream_wrap.js @@ -118,9 +118,8 @@ StreamWrap.prototype.doWrite = function doWrite(req, bufs) { const item = self._enqueue('write', req); self.stream.cork(); - bufs.forEach(function(buf) { - self.stream.write(buf, done); - }); + for (var n = 0; n < bufs.length; n++) + self.stream.write(bufs[n], done); self.stream.uncork(); function done(err) {