Skip to content

Commit

Permalink
stream: avoid using forEach
Browse files Browse the repository at this point in the history
PR-URL: #11582
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
jasnell authored and italoacasas committed Mar 20, 2017
1 parent 2cab00a commit 90be5a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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.
Expand Down Expand Up @@ -811,10 +813,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.
Expand Down
5 changes: 2 additions & 3 deletions lib/_stream_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 90be5a1

Please sign in to comment.