diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-12-05 07:51:47 +0100 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-12-07 10:16:10 -0800 |
commit | 254398a0be4eebf94fd244d1e331df7ec41d8f1e (patch) | |
tree | 84e8f91a84cc41885233aa4e4580f748210a003c /lib | |
parent | 46aa7d091fbfaf9d18a46d821dbabf3b4f34119d (diff) | |
download | android-node-v8-254398a0be4eebf94fd244d1e331df7ec41d8f1e.tar.gz android-node-v8-254398a0be4eebf94fd244d1e331df7ec41d8f1e.tar.bz2 android-node-v8-254398a0be4eebf94fd244d1e331df7ec41d8f1e.zip |
readline: eagerly load string_decoder
There was no point in lazy loading the string_decoder, since it
would be used in all cases anyway.
PR-URL: https://github.com/nodejs/node/pull/30807
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/readline.js | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/readline.js b/lib/readline.js index b25cf9ee64..630359aeb6 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -64,8 +64,7 @@ const { kClearScreenDown } = CSI; -// Lazy load StringDecoder for startup performance. -let StringDecoder; +const { StringDecoder } = require('string_decoder'); // Lazy load Readable for startup performance. let Readable; @@ -93,9 +92,6 @@ 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; @@ -1131,8 +1127,6 @@ Interface.prototype[Symbol.asyncIterator] = function() { 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); @@ -1147,8 +1141,11 @@ function emitKeypressEvents(stream, iface) { if (r) { clearTimeout(timeoutId); + let escapeTimeout = ESCAPE_CODE_TIMEOUT; + if (iface) { iface._sawKeyPress = r.length === 1; + escapeTimeout = iface.escapeCodeTimeout; } for (let i = 0; i < r.length; i++) { @@ -1160,10 +1157,7 @@ function emitKeypressEvents(stream, iface) { stream[ESCAPE_DECODER].next(r[i]); // Escape letter at the tail position if (r[i] === kEscape && i + 1 === r.length) { - timeoutId = setTimeout( - escapeCodeTimeout, - iface ? iface.escapeCodeTimeout : ESCAPE_CODE_TIMEOUT - ); + timeoutId = setTimeout(escapeCodeTimeout, escapeTimeout); } } catch (err) { // If the generator throws (it could happen in the `keypress` |