Skip to content

Commit

Permalink
stream: remove LazyTransform
Browse files Browse the repository at this point in the history
No longer necessary given recent stream and event optimziations.

Refs: #50428
Refs: #50439

PR-URL: #50440
  • Loading branch information
ronag committed Oct 29, 2023
1 parent 2aaa21f commit 3bab912
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 75 deletions.
21 changes: 21 additions & 0 deletions benchmark/crypto/hash-stream-creation2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Creation benchmark
// creates a single hasher, then pushes a minimal data through it
'use strict';
const common = require('../common.js');
const crypto = require('crypto');

const bench = common.createBenchmark(main, {
n: [10e3],
algo: ['md5' ],
});

const buf = Buffer.alloc(4);

function main({ algo, n }) {
bench.start();
for (let i = 0; i < n; ++i) {
const h = crypto.createHash(algo);
h.end(buf);
}
bench.end(n);
}
20 changes: 10 additions & 10 deletions lib/internal/crypto/cipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const {

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

const LazyTransform = require('internal/streams/lazy_transform');
const Transform = require('internal/streams/transform');

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

Expand Down Expand Up @@ -122,7 +122,7 @@ function createCipherBase(cipher, credential, options, decipher, iv) {
}
this._decoder = null;

ReflectApply(LazyTransform, this, [options]);
ReflectApply(Transform, this, [options]);
}

function createCipher(cipher, password, options, decipher) {
Expand Down Expand Up @@ -152,8 +152,8 @@ function Cipher(cipher, password, options) {
ReflectApply(createCipher, this, [cipher, password, options, true]);
}

ObjectSetPrototypeOf(Cipher.prototype, LazyTransform.prototype);
ObjectSetPrototypeOf(Cipher, LazyTransform);
ObjectSetPrototypeOf(Cipher.prototype, Transform.prototype);
ObjectSetPrototypeOf(Cipher, Transform);

Cipher.prototype._transform = function _transform(chunk, encoding, callback) {
this.push(this[kHandle].update(chunk, encoding));
Expand Down Expand Up @@ -257,8 +257,8 @@ function addCipherPrototypeFunctions(constructor) {
constructor.prototype.setAAD = Cipher.prototype.setAAD;
}

ObjectSetPrototypeOf(Cipheriv.prototype, LazyTransform.prototype);
ObjectSetPrototypeOf(Cipheriv, LazyTransform);
ObjectSetPrototypeOf(Cipheriv.prototype, Transform.prototype);
ObjectSetPrototypeOf(Cipheriv, Transform);
addCipherPrototypeFunctions(Cipheriv);

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

ObjectSetPrototypeOf(Decipher.prototype, LazyTransform.prototype);
ObjectSetPrototypeOf(Decipher, LazyTransform);
ObjectSetPrototypeOf(Decipher.prototype, Transform.prototype);
ObjectSetPrototypeOf(Decipher, Transform);
addCipherPrototypeFunctions(Decipher);

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

ObjectSetPrototypeOf(Decipheriv.prototype, LazyTransform.prototype);
ObjectSetPrototypeOf(Decipheriv, LazyTransform);
ObjectSetPrototypeOf(Decipheriv.prototype, Transform.prototype);
ObjectSetPrototypeOf(Decipheriv, Transform);
addCipherPrototypeFunctions(Decipheriv);

function getCipherInfo(nameOrNid, options) {
Expand Down
14 changes: 7 additions & 7 deletions lib/internal/crypto/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const {
isArrayBufferView,
} = require('internal/util/types');

const LazyTransform = require('internal/streams/lazy_transform');
const Transform = require('internal/streams/transform');

const kState = Symbol('kState');
const kFinalized = Symbol('kFinalized');
Expand All @@ -69,11 +69,11 @@ function Hash(algorithm, options) {
this[kState] = {
[kFinalized]: false,
};
ReflectApply(LazyTransform, this, [options]);
ReflectApply(Transform, this, [options]);
}

ObjectSetPrototypeOf(Hash.prototype, LazyTransform.prototype);
ObjectSetPrototypeOf(Hash, LazyTransform);
ObjectSetPrototypeOf(Hash.prototype, Transform.prototype);
ObjectSetPrototypeOf(Hash, Transform);

Hash.prototype.copy = function copy(options) {
const state = this[kState];
Expand Down Expand Up @@ -133,11 +133,11 @@ function Hmac(hmac, key, options) {
this[kState] = {
[kFinalized]: false,
};
ReflectApply(LazyTransform, this, [options]);
ReflectApply(Transform, this, [options]);
}

ObjectSetPrototypeOf(Hmac.prototype, LazyTransform.prototype);
ObjectSetPrototypeOf(Hmac, LazyTransform);
ObjectSetPrototypeOf(Hmac.prototype, Transform.prototype);
ObjectSetPrototypeOf(Hmac, Transform);

Hmac.prototype.update = Hash.prototype.update;

Expand Down
57 changes: 0 additions & 57 deletions lib/internal/streams/lazy_transform.js

This file was deleted.

1 change: 0 additions & 1 deletion src/node_builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const {
"internal/tls/parse-cert-string", "internal/tls/secure-context",
"internal/http2/core", "internal/http2/compat",
"internal/policy/manifest", "internal/process/policy",
"internal/streams/lazy_transform",
#endif // !HAVE_OPENSSL
"sys", // Deprecated.
"wasi", // Experimental.
Expand Down

0 comments on commit 3bab912

Please sign in to comment.