string_decoder: lazy loaded · nodejs/node@0ace8f9 · GitHub
Skip to content

Commit 0ace8f9

Browse files
BridgeARMylesBorins
authored andcommitted
string_decoder: lazy loaded
PR-URL: #20567 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 526163c commit 0ace8f9

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

lib/_stream_readable.js

Lines changed: 3 additions & 1 deletion

lib/internal/child_process.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const {
1414
ERR_MISSING_ARGS
1515
}
1616
} = require('internal/errors');
17-
const { StringDecoder } = require('string_decoder');
1817
const EventEmitter = require('events');
1918
const net = require('net');
2019
const dgram = require('dgram');
@@ -47,6 +46,9 @@ const {
4746

4847
const { SocketListSend, SocketListReceive } = SocketList;
4948

49+
// Lazy loaded for startup performance.
50+
let StringDecoder;
51+
5052
const MAX_HANDLE_RETRANSMISSIONS = 3;
5153

5254
// this object contain function to convert TCP objects to native handle objects
@@ -476,6 +478,8 @@ function setupChannel(target, channel) {
476478

477479
const control = new Control(channel);
478480

481+
if (StringDecoder === undefined)
482+
StringDecoder = require('string_decoder').StringDecoder;
479483
var decoder = new StringDecoder('utf8');
480484
var jsonBuffer = '';
481485
var pendingHandle = null;

lib/internal/crypto/cipher.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ const {
2828

2929
const assert = require('assert');
3030
const LazyTransform = require('internal/streams/lazy_transform');
31-
const { StringDecoder } = require('string_decoder');
3231

3332
const { inherits } = require('util');
3433
const { deprecate, normalizeEncoding } = require('internal/util');
3534

35+
// Lazy loaded for startup performance.
36+
let StringDecoder;
37+
3638
function rsaFunctionFor(method, defaultPadding) {
3739
return function(options, buffer) {
3840
const key = options.key || options;
@@ -49,6 +51,8 @@ const privateDecrypt = rsaFunctionFor(_privateDecrypt, RSA_PKCS1_OAEP_PADDING);
4951

5052
function getDecoder(decoder, encoding) {
5153
encoding = normalizeEncoding(encoding);
54+
if (StringDecoder === undefined)
55+
StringDecoder = require('string_decoder').StringDecoder;
5256
decoder = decoder || new StringDecoder(encoding);
5357
assert(decoder.encoding === encoding, 'Cannot change encoding');
5458
return decoder;

lib/readline.js

Lines changed: 9 additions & 1 deletion

0 commit comments

Comments
 (0)