stream: avoid using forEach
PR-URL: https://github.com/nodejs/node/pull/11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Родитель
c8acd08a37
Коммит
910a8998fb
|
@ -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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче