Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: remove LazyTransform #50440

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
21 changes: 11 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,8 @@ function createCipherBase(cipher, credential, options, decipher, iv) {
}
this._decoder = null;

ReflectApply(LazyTransform, this, [options]);
ReflectApply(Transform, this, [options]);
this._writableState.decodeStrings = false;
}

function createCipher(cipher, password, options, decipher) {
Expand Down Expand Up @@ -152,8 +153,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 +258,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 +274,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 +290,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
15 changes: 8 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,12 @@ function Hash(algorithm, options) {
this[kState] = {
[kFinalized]: false,
};
ReflectApply(LazyTransform, this, [options]);
ReflectApply(Transform, this, [options]);
this._writableState.decodeStrings = false;
}

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 +134,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