Skip to content

Commit

Permalink
repl: use String#repeat instead of Array#join
Browse files Browse the repository at this point in the history
String#repeat is quite a bit faster than new Array().join().

PR-URL: #3900
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
  • Loading branch information
evanlucas committed Dec 21, 2015
1 parent 14f81a0 commit 50125e2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ REPLServer.prototype.displayPrompt = function(preserveCursor) {
var prompt = this._initialPrompt;
if (this.bufferedCommand.length) {
prompt = '...';
var levelInd = new Array(this.lines.level.length).join('..');
const len = this.lines.level.length ? this.lines.level.length - 1 : 0;
const levelInd = '..'.repeat(len);
prompt += levelInd + ' ';
}

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

0 comments on commit 50125e2

Please sign in to comment.