GeezerVison is showing github.com — repl: fix cpu overhead pasting big strings to the REPL · nodejs/node@e790eb6
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/readline/interface.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -624,6 +624,12 @@ class Interface extends InterfaceConstructor { |
624 | 624 |
|
625 | 625 | [kInsertString](c) { |
626 | 626 | this[kBeforeEdit](this.line, this.cursor); |
| 627 | + if (!this.isCompletionEnabled) { |
| 628 | + this.line += c; |
| 629 | + this.cursor += c.length; |
| 630 | + this[kWriteToOutput](c); |
| 631 | + return; |
| 632 | + } |
627 | 633 | if (this.cursor < this.line.length) { |
628 | 634 | const beg = StringPrototypeSlice(this.line, 0, this.cursor); |
629 | 635 | const end = StringPrototypeSlice( |
|
Collapse file
Copy file name to clipboard +36Lines changed: 36 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const repl = require('repl'); |
| 5 | +const stream = require('stream'); |
| 6 | +const assert = require('assert'); |
| 7 | + |
| 8 | +// Pasting big input should not cause the process to have a huge CPU usage. |
| 9 | + |
| 10 | +const cpuUsage = process.cpuUsage(); |
| 11 | + |
| 12 | +const r = initRepl(); |
| 13 | +r.input.emit('data', 'a'.repeat(2e4) + '\n'); |
| 14 | +r.input.emit('data', '.exit\n'); |
| 15 | + |
| 16 | +r.once('exit', common.mustCall(() => { |
| 17 | + const diff = process.cpuUsage(cpuUsage); |
| 18 | + assert.ok(diff.user < 1e6); |
| 19 | +})); |
| 20 | + |
| 21 | +function initRepl() { |
| 22 | + const input = new stream(); |
| 23 | + input.write = input.pause = input.resume = () => {}; |
| 24 | + input.readable = true; |
| 25 | + |
| 26 | + const output = new stream(); |
| 27 | + output.write = () => {}; |
| 28 | + output.writable = true; |
| 29 | + |
| 30 | + return repl.start({ |
| 31 | + input, |
| 32 | + output, |
| 33 | + terminal: true, |
| 34 | + prompt: '' |
| 35 | + }); |
| 36 | +} |