repl: use String#repeat instead of Array#join
authorEvan Lucas <evanlucas@me.com>
Wed, 18 Nov 2015 12:59:43 +0000 (06:59 -0600)
committerMyles Borins <mborins@us.ibm.com>
Tue, 19 Jan 2016 19:52:30 +0000 (11:52 -0800)
String#repeat is quite a bit faster than new Array().join().

PR-URL: https://github.com/nodejs/node/pull/3900
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
lib/repl.js

index 84ac726..9c80ee5 100644 (file)
@@ -554,7 +554,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 + ' ';
   }
 
@@ -906,7 +907,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('');