diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-06 23:08:00 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-18 15:25:38 +0200 |
commit | f4f8b22f7d474a9206ce1253cf884b94552759f3 (patch) | |
tree | ac20cddcbd11a364d597fdf253022980134bd81b | |
parent | 11892b0b6422f6e983bfbde7ba342942dd2e2297 (diff) | |
download | android-node-v8-f4f8b22f7d474a9206ce1253cf884b94552759f3.tar.gz android-node-v8-f4f8b22f7d474a9206ce1253cf884b94552759f3.tar.bz2 android-node-v8-f4f8b22f7d474a9206ce1253cf884b94552759f3.zip |
string_decoder: lazy loaded
PR-URL: https://github.com/nodejs/node/pull/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>
-rw-r--r-- | lib/_stream_readable.js | 4 | ||||
-rw-r--r-- | lib/internal/child_process.js | 6 | ||||
-rw-r--r-- | lib/internal/crypto/cipher.js | 6 | ||||
-rw-r--r-- | lib/readline.js | 10 |
4 files changed, 22 insertions, 4 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 3b614a7924..ecdcccc064 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -40,7 +40,9 @@ const { } = require('internal/errors').codes; const ReadableAsyncIterator = require('internal/streams/async_iterator'); const { emitExperimentalWarning } = require('internal/util'); -var StringDecoder; + +// Lazy loaded to improve the startup performance. +let StringDecoder; util.inherits(Readable, Stream); diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index a630cff717..1ec3f20866 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -14,7 +14,6 @@ const { ERR_MISSING_ARGS } } = require('internal/errors'); -const { StringDecoder } = require('string_decoder'); const EventEmitter = require('events'); const net = require('net'); const dgram = require('dgram'); @@ -47,6 +46,9 @@ const { const { SocketListSend, SocketListReceive } = SocketList; +// Lazy loaded for startup performance. +let StringDecoder; + const MAX_HANDLE_RETRANSMISSIONS = 3; // this object contain function to convert TCP objects to native handle objects @@ -476,6 +478,8 @@ function setupChannel(target, channel) { const control = new Control(channel); + if (StringDecoder === undefined) + StringDecoder = require('string_decoder').StringDecoder; var decoder = new StringDecoder('utf8'); var jsonBuffer = ''; var pendingHandle = null; diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js index d1c45bfdce..bd80c19697 100644 --- a/lib/internal/crypto/cipher.js +++ b/lib/internal/crypto/cipher.js @@ -28,11 +28,13 @@ const { const assert = require('assert'); const LazyTransform = require('internal/streams/lazy_transform'); -const { StringDecoder } = require('string_decoder'); const { inherits } = require('util'); const { normalizeEncoding } = require('internal/util'); +// Lazy loaded for startup performance. +let StringDecoder; + function rsaFunctionFor(method, defaultPadding) { return function(options, buffer) { const key = options.key || options; @@ -49,6 +51,8 @@ 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/readline.js b/lib/readline.js index 124fc8111b..89dd1b84f2 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -35,7 +35,6 @@ const { const { debug, inherits } = require('util'); const { Buffer } = require('buffer'); const EventEmitter = require('events'); -const { StringDecoder } = require('string_decoder'); const { CSI, emitKeys, @@ -52,6 +51,9 @@ const { kClearScreenDown } = CSI; +// Lazy load StringDecoder for startup performance. +let StringDecoder; + const kHistorySize = 30; const kMincrlfDelay = 100; // \r\n, \n, or \r followed by something other than \n @@ -73,6 +75,9 @@ function Interface(input, output, completer, terminal) { return new Interface(input, output, completer, terminal); } + if (StringDecoder === undefined) + StringDecoder = require('string_decoder').StringDecoder; + this._sawReturnAt = 0; this.isCompletionEnabled = true; this._sawKeyPress = false; @@ -987,6 +992,9 @@ Interface.prototype._ttyWrite = function(s, key) { function emitKeypressEvents(stream, iface) { if (stream[KEYPRESS_DECODER]) return; + + if (StringDecoder === undefined) + StringDecoder = require('string_decoder').StringDecoder; stream[KEYPRESS_DECODER] = new StringDecoder('utf8'); stream[ESCAPE_DECODER] = emitKeys(stream); |