Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2021-05-19 21:32:18 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2021-05-31 22:34:56 +0300
commit7d3a8cb8541945c40e0e0444697f8a9ab0cf4465 (patch)
tree9a72f96f0376becb31eb35ff8cdc3dbf89e26d8b /lib
parent5d9442a024622327fdb7b4c158bb10a6d3461931 (diff)
lib: remove unnecessary lazy loads
Now that more modules are included in the snapshot, it's not necessary to lazy load them anymore PR-URL: https://github.com/nodejs/node/pull/38737 Refs: https://github.com/nodejs/node/issues/35711 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/crypto/cipher.js5
-rw-r--r--lib/internal/streams/pipeline.js3
-rw-r--r--lib/internal/streams/readable.js12
-rw-r--r--lib/stream.js14
-rw-r--r--lib/stream/promises.js6
5 files changed, 10 insertions, 30 deletions
diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js
index 1b6ad0e7ea6..d85606ba52b 100644
--- a/lib/internal/crypto/cipher.js
+++ b/lib/internal/crypto/cipher.js
@@ -60,8 +60,7 @@ const LazyTransform = require('internal/streams/lazy_transform');
const { normalizeEncoding } = require('internal/util');
-// Lazy loaded for startup performance.
-let StringDecoder;
+const { StringDecoder } = require('string_decoder');
function rsaFunctionFor(method, defaultPadding, keyType) {
return (options, buffer) => {
@@ -93,8 +92,6 @@ const privateDecrypt = rsaFunctionFor(_privateDecrypt, RSA_PKCS1_OAEP_PADDING,
function getDecoder(decoder, encoding) {
encoding = normalizeEncoding(encoding);
- if (StringDecoder === undefined)
- StringDecoder = require('string_decoder').StringDecoder;
decoder = decoder || new StringDecoder(encoding);
assert(decoder.encoding === encoding, 'Cannot change encoding');
return decoder;
diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js
index 441fcb47185..f5b6fb90e11 100644
--- a/lib/internal/streams/pipeline.js
+++ b/lib/internal/streams/pipeline.js
@@ -8,7 +8,7 @@ const {
SymbolAsyncIterator,
} = primordials;
-let eos;
+const eos = require('internal/streams/end-of-stream');
const { once } = require('internal/util');
const destroyImpl = require('internal/streams/destroy');
@@ -39,7 +39,6 @@ function destroyer(stream, reading, writing, callback) {
finished = true;
});
- if (eos === undefined) eos = require('internal/streams/end-of-stream');
eos(stream, { readable: reading, writable: writing }, (err) => {
finished = !err;
diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js
index 2a818db22df..7f6876599cc 100644
--- a/lib/internal/streams/readable.js
+++ b/lib/internal/streams/readable.js
@@ -66,9 +66,8 @@ const { validateObject } = require('internal/validators');
const kPaused = Symbol('kPaused');
-// Lazy loaded to improve the startup performance.
-let StringDecoder;
-let from;
+const { StringDecoder } = require('string_decoder');
+const from = require('internal/streams/from');
ObjectSetPrototypeOf(Readable.prototype, Stream.prototype);
ObjectSetPrototypeOf(Readable, Stream);
@@ -171,8 +170,6 @@ function ReadableState(options, stream, isDuplex) {
this.decoder = null;
this.encoding = null;
if (options && options.encoding) {
- if (!StringDecoder)
- StringDecoder = require('string_decoder').StringDecoder;
this.decoder = new StringDecoder(options.encoding);
this.encoding = options.encoding;
}
@@ -334,8 +331,6 @@ Readable.prototype.isPaused = function() {
// Backwards compatibility.
Readable.prototype.setEncoding = function(enc) {
- if (!StringDecoder)
- StringDecoder = require('string_decoder').StringDecoder;
const decoder = new StringDecoder(enc);
this._readableState.decoder = decoder;
// If setEncoding(null), decoder.encoding equals utf8.
@@ -1362,8 +1357,5 @@ function endWritableNT(state, stream) {
}
Readable.from = function(iterable, opts) {
- if (from === undefined) {
- from = require('internal/streams/from');
- }
return from(Readable, iterable, opts);
};
diff --git a/lib/stream.js b/lib/stream.js
index 1697a2f2729..85adda81b32 100644
--- a/lib/stream.js
+++ b/lib/stream.js
@@ -33,8 +33,7 @@ const pipeline = require('internal/streams/pipeline');
const eos = require('internal/streams/end-of-stream');
const internalBuffer = require('internal/buffer');
-// Lazy loaded
-let promises = null;
+const promises = require('stream/promises');
const Stream = module.exports = require('internal/streams/legacy').Stream;
Stream.Readable = require('internal/streams/readable');
@@ -47,30 +46,25 @@ const { addAbortSignal } = require('internal/streams/add-abort-signal');
Stream.addAbortSignal = addAbortSignal;
Stream.finished = eos;
-function lazyLoadPromises() {
- if (promises === null) promises = require('stream/promises');
- return promises;
-}
-
ObjectDefineProperty(Stream, 'promises', {
configurable: true,
enumerable: true,
get() {
- return lazyLoadPromises();
+ return promises;
}
});
ObjectDefineProperty(pipeline, customPromisify, {
enumerable: true,
get() {
- return lazyLoadPromises().pipeline;
+ return promises.pipeline;
}
});
ObjectDefineProperty(eos, customPromisify, {
enumerable: true,
get() {
- return lazyLoadPromises().finished;
+ return promises.finished;
}
});
diff --git a/lib/stream/promises.js b/lib/stream/promises.js
index 027579b878d..f5d87319732 100644
--- a/lib/stream/promises.js
+++ b/lib/stream/promises.js
@@ -18,11 +18,10 @@ const {
isStream,
} = require('internal/streams/utils');
-let pl;
-let eos;
+const pl = require('internal/streams/pipeline');
+const eos = require('internal/streams/end-of-stream');
function pipeline(...streams) {
- if (!pl) pl = require('internal/streams/pipeline');
return new Promise((resolve, reject) => {
let signal;
const lastArg = streams[streams.length - 1];
@@ -47,7 +46,6 @@ function pipeline(...streams) {
}
function finished(stream, opts) {
- if (!eos) eos = require('internal/streams/end-of-stream');
return new Promise((resolve, reject) => {
eos(stream, opts, (err) => {
if (err) {