Skip to content

Commit

Permalink
lib: avoid using forEach in LazyTransform
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 committed Mar 17, 2017
1 parent a993beb commit 4d09085
Showing 1 changed file with 41 additions and 25 deletions.
66 changes: 41 additions & 25 deletions lib/internal/streams/lazy_transform.js
Expand Up @@ -14,31 +14,47 @@ function LazyTransform(options) {
} }
util.inherits(LazyTransform, stream.Transform); util.inherits(LazyTransform, stream.Transform);


[ function makeGetter(name) {
'_readableState', return function() {
'_writableState', stream.Transform.call(this, this._options);
'_transformState' this._writableState.decodeStrings = false;
].forEach(function(prop, i, props) {
Object.defineProperty(LazyTransform.prototype, prop, { if (!this._options || !this._options.defaultEncoding) {
get: function() { this._writableState.defaultEncoding = crypto.DEFAULT_ENCODING;
stream.Transform.call(this, this._options); }
this._writableState.decodeStrings = false;

return this[name];
if (!this._options || !this._options.defaultEncoding) { };
this._writableState.defaultEncoding = crypto.DEFAULT_ENCODING; }
}

function makeSetter(name) {
return this[prop]; return function(val) {
}, Object.defineProperty(this, name, {
set: function(val) { value: val,
Object.defineProperty(this, prop, { enumerable: true,
value: val, configurable: true,
enumerable: true, writable: true
configurable: true, });
writable: true };
}); }
},
Object.defineProperties(LazyTransform.prototype, {
_readableState: {
get: makeGetter('_readableState'),
set: makeSetter('_readableState'),
configurable: true,
enumerable: true
},
_writableState: {
get: makeGetter('_writableState'),
set: makeSetter('_writableState'),
configurable: true,
enumerable: true
},
_transformState: {
get: makeGetter('_transformState'),
set: makeSetter('_transformState'),
configurable: true, configurable: true,
enumerable: true enumerable: true
}); }
}); });

0 comments on commit 4d09085

Please sign in to comment.