Skip to content

Commit d260d0c

Browse files
evanlucasMichael Scovetta
authored and
Michael Scovetta
committed
repl: use String#repeat instead of Array#join
String#repeat is quite a bit faster than new Array().join(). PR-URL: nodejs#3900 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
1 parent 038e946 commit d260d0c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/repl.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,8 @@ REPLServer.prototype.displayPrompt = function(preserveCursor) {
568568
var prompt = this._initialPrompt;
569569
if (this.bufferedCommand.length) {
570570
prompt = '...';
571-
var levelInd = new Array(this.lines.level.length).join('..');
571+
const len = this.lines.level.length ? this.lines.level.length - 1 : 0;
572+
const levelInd = '..'.repeat(len);
572573
prompt += levelInd + ' ';
573574
}
574575

@@ -920,7 +921,8 @@ REPLServer.prototype.memory = function memory(cmd) {
920921
// save the line so I can do magic later
921922
if (cmd) {
922923
// TODO should I tab the level?
923-
self.lines.push(new Array(self.lines.level.length).join(' ') + cmd);
924+
const len = self.lines.level.length ? self.lines.level.length - 1 : 0;
925+
self.lines.push(' '.repeat(len) + cmd);
924926
} else {
925927
// I don't want to not change the format too much...
926928
self.lines.push('');

0 commit comments

Comments
 (0)