Skip to content

Commit 9855fab

Browse files
evanlucasMyles Borins
authored and
Myles Borins
committed
repl: use String#repeat instead of Array#join
String#repeat is quite a bit faster than new Array().join(). PR-URL: #3900 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
1 parent 9baa561 commit 9855fab

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
@@ -554,7 +554,8 @@ REPLServer.prototype.displayPrompt = function(preserveCursor) {
554554
var prompt = this._initialPrompt;
555555
if (this.bufferedCommand.length) {
556556
prompt = '...';
557-
var levelInd = new Array(this.lines.level.length).join('..');
557+
const len = this.lines.level.length ? this.lines.level.length - 1 : 0;
558+
const levelInd = '..'.repeat(len);
558559
prompt += levelInd + ' ';
559560
}
560561

@@ -906,7 +907,8 @@ REPLServer.prototype.memory = function memory(cmd) {
906907
// save the line so I can do magic later
907908
if (cmd) {
908909
// TODO should I tab the level?
909-
self.lines.push(new Array(self.lines.level.length).join(' ') + cmd);
910+
const len = self.lines.level.length ? self.lines.level.length - 1 : 0;
911+
self.lines.push(' '.repeat(len) + cmd);
910912
} else {
911913
// I don't want to not change the format too much...
912914
self.lines.push('');

0 commit comments

Comments
 (0)