Skip to content

Commit 910a899

Browse files
committed
stream: avoid using forEach
PR-URL: #11582 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent c8acd08 commit 910a899

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/_stream_readable.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ var StringDecoder;
3434

3535
util.inherits(Readable, Stream);
3636

37+
const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
38+
3739
function prependListener(emitter, event, fn) {
3840
// Sadly this is not cacheable as some libraries bundle their own
3941
// event emitter implementation with them.
@@ -828,10 +830,9 @@ Readable.prototype.wrap = function(stream) {
828830
}
829831

830832
// proxy certain important events.
831-
const events = ['error', 'close', 'destroy', 'pause', 'resume'];
832-
events.forEach(function(ev) {
833-
stream.on(ev, self.emit.bind(self, ev));
834-
});
833+
for (var n = 0; n < kProxyEvents.length; n++) {
834+
stream.on(kProxyEvents[n], self.emit.bind(self, kProxyEvents[n]));
835+
}
835836

836837
// when we try to consume some more bytes, simply unpause the
837838
// underlying stream.

lib/_stream_wrap.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ StreamWrap.prototype.doWrite = function doWrite(req, bufs) {
118118
const item = self._enqueue('write', req);
119119

120120
self.stream.cork();
121-
bufs.forEach(function(buf) {
122-
self.stream.write(buf, done);
123-
});
121+
for (var n = 0; n < bufs.length; n++)
122+
self.stream.write(bufs[n], done);
124123
self.stream.uncork();
125124

126125
function done(err) {

0 commit comments

Comments
 (0)