Skip to content

Commit 3bab912

Browse files
committed
stream: remove LazyTransform
No longer necessary given recent stream and event optimziations. Refs: nodejs#50428 Refs: nodejs#50439 PR-URL: nodejs#50440
1 parent 2aaa21f commit 3bab912

File tree

5 files changed

+38
-75
lines changed

5 files changed

+38
-75
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Creation benchmark
2+
// creates a single hasher, then pushes a minimal data through it
3+
'use strict';
4+
const common = require('../common.js');
5+
const crypto = require('crypto');
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [10e3],
9+
algo: ['md5' ],
10+
});
11+
12+
const buf = Buffer.alloc(4);
13+
14+
function main({ algo, n }) {
15+
bench.start();
16+
for (let i = 0; i < n; ++i) {
17+
const h = crypto.createHash(algo);
18+
h.end(buf);
19+
}
20+
bench.end(n);
21+
}

lib/internal/crypto/cipher.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const {
5656

5757
const assert = require('internal/assert');
5858

59-
const LazyTransform = require('internal/streams/lazy_transform');
59+
const Transform = require('internal/streams/transform');
6060

6161
const { normalizeEncoding } = require('internal/util');
6262

@@ -122,7 +122,7 @@ function createCipherBase(cipher, credential, options, decipher, iv) {
122122
}
123123
this._decoder = null;
124124

125-
ReflectApply(LazyTransform, this, [options]);
125+
ReflectApply(Transform, this, [options]);
126126
}
127127

128128
function createCipher(cipher, password, options, decipher) {
@@ -152,8 +152,8 @@ function Cipher(cipher, password, options) {
152152
ReflectApply(createCipher, this, [cipher, password, options, true]);
153153
}
154154

155-
ObjectSetPrototypeOf(Cipher.prototype, LazyTransform.prototype);
156-
ObjectSetPrototypeOf(Cipher, LazyTransform);
155+
ObjectSetPrototypeOf(Cipher.prototype, Transform.prototype);
156+
ObjectSetPrototypeOf(Cipher, Transform);
157157

158158
Cipher.prototype._transform = function _transform(chunk, encoding, callback) {
159159
this.push(this[kHandle].update(chunk, encoding));
@@ -257,8 +257,8 @@ function addCipherPrototypeFunctions(constructor) {
257257
constructor.prototype.setAAD = Cipher.prototype.setAAD;
258258
}
259259

260-
ObjectSetPrototypeOf(Cipheriv.prototype, LazyTransform.prototype);
261-
ObjectSetPrototypeOf(Cipheriv, LazyTransform);
260+
ObjectSetPrototypeOf(Cipheriv.prototype, Transform.prototype);
261+
ObjectSetPrototypeOf(Cipheriv, Transform);
262262
addCipherPrototypeFunctions(Cipheriv);
263263

264264
// The Decipher class is part of the legacy Node.js crypto API. It exposes
@@ -273,8 +273,8 @@ function Decipher(cipher, password, options) {
273273
ReflectApply(createCipher, this, [cipher, password, options, false]);
274274
}
275275

276-
ObjectSetPrototypeOf(Decipher.prototype, LazyTransform.prototype);
277-
ObjectSetPrototypeOf(Decipher, LazyTransform);
276+
ObjectSetPrototypeOf(Decipher.prototype, Transform.prototype);
277+
ObjectSetPrototypeOf(Decipher, Transform);
278278
addCipherPrototypeFunctions(Decipher);
279279

280280
// The Decipheriv class is part of the legacy Node.js crypto API. It exposes
@@ -289,8 +289,8 @@ function Decipheriv(cipher, key, iv, options) {
289289
ReflectApply(createCipherWithIV, this, [cipher, key, options, false, iv]);
290290
}
291291

292-
ObjectSetPrototypeOf(Decipheriv.prototype, LazyTransform.prototype);
293-
ObjectSetPrototypeOf(Decipheriv, LazyTransform);
292+
ObjectSetPrototypeOf(Decipheriv.prototype, Transform.prototype);
293+
ObjectSetPrototypeOf(Decipheriv, Transform);
294294
addCipherPrototypeFunctions(Decipheriv);
295295

296296
function getCipherInfo(nameOrNid, options) {

lib/internal/crypto/hash.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const {
5151
isArrayBufferView,
5252
} = require('internal/util/types');
5353

54-
const LazyTransform = require('internal/streams/lazy_transform');
54+
const Transform = require('internal/streams/transform');
5555

5656
const kState = Symbol('kState');
5757
const kFinalized = Symbol('kFinalized');
@@ -69,11 +69,11 @@ function Hash(algorithm, options) {
6969
this[kState] = {
7070
[kFinalized]: false,
7171
};
72-
ReflectApply(LazyTransform, this, [options]);
72+
ReflectApply(Transform, this, [options]);
7373
}
7474

75-
ObjectSetPrototypeOf(Hash.prototype, LazyTransform.prototype);
76-
ObjectSetPrototypeOf(Hash, LazyTransform);
75+
ObjectSetPrototypeOf(Hash.prototype, Transform.prototype);
76+
ObjectSetPrototypeOf(Hash, Transform);
7777

7878
Hash.prototype.copy = function copy(options) {
7979
const state = this[kState];
@@ -133,11 +133,11 @@ function Hmac(hmac, key, options) {
133133
this[kState] = {
134134
[kFinalized]: false,
135135
};
136-
ReflectApply(LazyTransform, this, [options]);
136+
ReflectApply(Transform, this, [options]);
137137
}
138138

139-
ObjectSetPrototypeOf(Hmac.prototype, LazyTransform.prototype);
140-
ObjectSetPrototypeOf(Hmac, LazyTransform);
139+
ObjectSetPrototypeOf(Hmac.prototype, Transform.prototype);
140+
ObjectSetPrototypeOf(Hmac, Transform);
141141

142142
Hmac.prototype.update = Hash.prototype.update;
143143

lib/internal/streams/lazy_transform.js

-57
This file was deleted.

src/node_builtins.cc

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const {
125125
"internal/tls/parse-cert-string", "internal/tls/secure-context",
126126
"internal/http2/core", "internal/http2/compat",
127127
"internal/policy/manifest", "internal/process/policy",
128-
"internal/streams/lazy_transform",
129128
#endif // !HAVE_OPENSSL
130129
"sys", // Deprecated.
131130
"wasi", // Experimental.

0 commit comments

Comments
 (0)