Bug 757299 (part 6) - Compute paths in a better way in aboutMemory.js. r=jlebar.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 27 May 2012 18:09:37 -0700
changeset 99155 2f11a356655439157333a03e9399609c24c33755
parent 99154 eff14a3bd0da51c814ca0db503ce569d38664735
child 99156 1d98ab2314e0e03fb481edd682ef1d6b12e26a4b
push idunknown
push userunknown
push dateunknown
reviewersjlebar
bugs757299
milestone15.0a1
Bug 757299 (part 6) - Compute paths in a better way in aboutMemory.js. r=jlebar.
toolkit/components/aboutmemory/content/aboutMemory.js
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -1191,43 +1191,41 @@ function appendTreeElements(aPOuter, aT,
   let rootStringLength = aT.toString().length;
   let isExplicitTree = aT._unsafeName == 'explicit';
 
   /**
    * Appends the elements for a particular tree, without a heading.
    *
    * @param aP
    *        The parent DOM node.
-   * @param aUnsafePrePath
-   *        The partial unsafePath leading up to this node.
+   * @param aUnsafeNames
+   *        An array of the names forming the path to aT.
    * @param aT
    *        The tree.
    * @param aBaseIndentText
    *        The base text of the indent, which may be augmented within the
    *        function.
    * @param aIndentGuide
    *        Records what indentation is required for this tree.  It has one
    *        entry per level of indentation.  For each entry, ._isLastKid
    *        records whether the node in question is the last child, and
    *        ._depth records how many chars of indentation are required.
    * @param aParentStringLength
    *        The length of the formatted byte count of the top node in the tree.
    */
-  function appendTreeElements2(aP, aUnsafePrePath, aT, aIndentGuide,
+  function appendTreeElements2(aP, aUnsafeNames, aT, aIndentGuide,
                                aBaseIndentText, aParentStringLength)
   {
     function repeatStr(aA, aC, aN)
     {
       for (let i = 0; i < aN; i++) {
         aA.push(aC);
       }
     }
 
-    let unsafePath = aUnsafePrePath + aT._unsafeName;
-
     // Indent more if this entry is narrower than its parent, and update
     // aIndentGuide accordingly.
     let tString = aT.toString();
     let extraIndentLength = Math.max(aParentStringLength - tString.length, 0);
     let indentText;
     if (extraIndentLength > 0) {
       let extraIndentArray = [];
       repeatStr(extraIndentArray, kHorizontal, extraIndentLength);
@@ -1243,16 +1241,17 @@ function appendTreeElements(aPOuter, aT,
     // time.
     let percText = "";
     let tIsInvalid = false;
     if (aT._amount === treeBytes) {
       percText = "100.0";
     } else {
       if (!(0 <= aT._amount && aT._amount <= treeBytes)) {
         tIsInvalid = true;
+        let unsafePath = aUnsafeNames.join("/");
         gUnsafePathsWithInvalidValuesForThisProcess.push(unsafePath);
         reportAssertionFailure("Invalid value for " +
                                flipBackslashes(unsafePath));
       }
       percText = (100 * aT._amount / treeBytes).toFixed(2);
       percText = pad(percText, 5, '0');
     }
     percText = " (" + percText + "%)";
@@ -1260,17 +1259,18 @@ function appendTreeElements(aPOuter, aT,
     // For non-leaf nodes, the entire sub-tree is put within a span so it can
     // be collapsed if the node is clicked on.
     let d;
     let sep;
     let showSubtrees;
     if (aT._kids) {
       // Determine if we should show the sub-tree below this entry;  this
       // involves reinstating any previous toggling of the sub-tree.
-      let safeTreeId = flipBackslashes(aProcess + ":" + unsafePath);
+      let unsafePath = aUnsafeNames.join("/");
+      let safeTreeId = aProcess + ":" + flipBackslashes(unsafePath);
       showSubtrees = !aT._hideKids;
       if (gShowSubtreesBySafeTreeId[safeTreeId] !== undefined) {
         showSubtrees = gShowSubtreesBySafeTreeId[safeTreeId];
       }
       d = appendElement(aP, "span", "hasKids");
       d.id = safeTreeId;
       d.onclick = toggle;
       sep = showSubtrees ? kShowKidsSep : kHideKidsSep;
@@ -1313,27 +1313,29 @@ function appendTreeElements(aPOuter, aT,
             repeatStr(baseIndentArray, " ", aIndentGuide[j]._depth - 1);
           }
           baseIndentArray.push(aIndentGuide[j]._isLastKid ?
                                kUpAndRight : kVerticalAndRight);
           repeatStr(baseIndentArray, kHorizontal, aIndentGuide[j]._depth - 1);
         }
 
         let baseIndentText = baseIndentArray.join("");
-        appendTreeElements2(d, unsafePath + "/", aT._kids[i], aIndentGuide,
+        aUnsafeNames.push(aT._kids[i]._unsafeName);
+        appendTreeElements2(d, aUnsafeNames, aT._kids[i], aIndentGuide,
                             baseIndentText, tString.length);
+        aUnsafeNames.pop();
         aIndentGuide.pop();
       }
     }
   }
 
   appendSectionHeader(aPOuter, kSectionNames[aT._unsafeName]);
  
   let pre = appendElement(aPOuter, "pre", "entries");
-  appendTreeElements2(pre, /* prePath = */"", aT, [], "", rootStringLength);
+  appendTreeElements2(pre, [aT._unsafeName], aT, [], "", rootStringLength);
   appendTextNode(aPOuter, "\n");  // gives nice spacing when we cut and paste
 }
 
 //---------------------------------------------------------------------------
 
 function OtherReport(aUnsafePath, aUnits, aAmount, aDescription, aNMerged)
 {
   // Nb: _kind is not needed, it's always KIND_OTHER.