Bug 1499906 (attempt 2) - Use String.prototype.padStart(). r=erahm
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 19 Oct 2018 15:11:39 +1100
changeset 490394 d8c9c172c24599b14ce744fd5b9f01f5916e5ae9
parent 490393 edee090da6bdce1e744b951145b0afa4ac4bd9d4
child 490395 1752794d80abffc53fe6ffa689fcd1648195b6af
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerserahm
bugs1499906
milestone64.0a1
Bug 1499906 (attempt 2) - Use String.prototype.padStart(). r=erahm
toolkit/components/aboutmemory/content/aboutMemory.js
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -1483,17 +1483,17 @@ function appendProcessAboutMemoryElement
 
   // Now generate the elements, putting non-degenerate trees first.
   let pre = appendSectionHeader(aP, "Other Measurements");
   for (let t of otherTrees) {
     appendTreeElements(pre, t, aProcess, "");
     appendTextNode(pre, "\n"); // blank lines after non-degenerate trees
   }
   for (let t of otherDegenerates) {
-    let padText = pad("", maxStringLength - t.toString().length, " ");
+    let padText = "".padStart(maxStringLength - t.toString().length, " ");
     appendTreeElements(pre, t, aProcess, padText);
   }
   appendTextNode(aP, "\n"); // gives nice spacing when we copy and paste
 
   // Add any warnings about inaccuracies in the "explicit" tree due to platform
   // limitations.  These must be computed after generating all the text.  The
   // newlines give nice spacing if we copy+paste into a text buffer.
   if (hasExplicitTree) {
@@ -1589,36 +1589,16 @@ function formatTreeFrac(aNum, aDenom) {
   //   alignment. For positive numbers, 00.00%--99.99% works straighforwardly,
   //   but 100.0% needs special handling.
   let num = aDenom === 0 ? 1 : (aNum / aDenom);
   return (0.99995 <= num && num <= 1)
          ? formatNum(1, kFrac1Style)
          : formatNum(num, kFracStyle);
 }
 
-/**
- * Right-justifies a string in a field of a given width, padding as necessary.
- *
- * @param aS
- *        The string.
- * @param aN
- *        The field width.
- * @param aC
- *        The char used to pad.
- * @return The string representation.
- */
-function pad(aS, aN, aC) {
-  let padding = "";
-  let n2 = aN - aS.length;
-  for (let i = 0; i < n2; i++) {
-    padding += aC;
-  }
-  return padding + aS;
-}
-
 const kNoKidsSep   = " ── ",
       kHideKidsSep = " ++ ",
       kShowKidsSep = " -- ";
 
 function appendMrNameSpan(aP, aDescription, aUnsafeName, aIsInvalid, aNMerged,
                           aPresence) {
   let safeName = flipBackslashes(aUnsafeName);
   if (!aIsInvalid && !aNMerged && !aPresence) {