Bug 757299 (part 4) - Don't put each newline in a separate text node in about:memory. r=jlebar.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 23 May 2012 17:06:35 -0700
changeset 99153 f7894fb36f72b4495b5c992756cb59cc1659e181
parent 99152 16dbfe2ae98b07cad83cb14567f187c051006958
child 99154 eff14a3bd0da51c814ca0db503ce569d38664735
push idunknown
push userunknown
push dateunknown
reviewersjlebar
bugs757299
milestone15.0a1
Bug 757299 (part 4) - Don't put each newline in a separate text node in about:memory. r=jlebar.
toolkit/components/aboutmemory/content/aboutMemory.js
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -1100,34 +1100,40 @@ function kindToString(aKind)
    case KIND_NONHEAP: return "(Non-heap) ";
    case KIND_HEAP:    return "(Heap) ";
    case KIND_OTHER:
    case undefined:    return "";
    default:           assert(false, "bad kind in kindToString");
   }
 }
 
-function appendMrNameSpan(aP, aKind, aSep, aDescription, aUnsafeName,
+function appendMrNameSpan(aP, aKind, aDescription, aUnsafeName,
                           aIsInvalid, aNMerged)
 {
-  appendElementWithText(aP, "span", "mrSep", aSep);
-
-  let nameSpan = appendElementWithText(aP, "span", "mrName",
-                                       flipBackslashes(aUnsafeName));
+  let safeName = flipBackslashes(aUnsafeName);
+  if (!aIsInvalid && !aNMerged) {
+    safeName += "\n";
+  }
+  let nameSpan = appendElementWithText(aP, "span", "mrName", safeName);
   nameSpan.title = kindToString(aKind) + aDescription;
 
   if (aIsInvalid) {
-    let noteSpan = appendElementWithText(aP, "span", "mrNote", " [?!]");
+    let noteText = " [?!]";
+    if (!aNMerged) {
+      noteText += "\n";
+    }
+    let noteSpan = appendElementWithText(aP, "span", "mrNote", noteText);
     noteSpan.title =
       "Warning: this value is invalid and indicates a bug in one or more " +
       "memory reporters. ";
   }
+
   if (aNMerged) {
     let noteSpan = appendElementWithText(aP, "span", "mrNote",
-                                         " [" + aNMerged + "]");
+                                         " [" + aNMerged + "]\n");
     noteSpan.title =
       "This value is the sum of " + aNMerged +
       " memory reporters that all have the same path.";
   }
 }
 
 // This is used to record the (safe) IDs of which sub-trees have been manually
 // expanded (marked as true) and collapsed (marked as false).  It's used to
@@ -1146,17 +1152,17 @@ function assertClassListContains(e, clas
 function toggle(aEvent)
 {
   // This relies on each line being a span that contains at least four spans:
   // mrValue, mrPerc, mrSep, mrName, and then zero or more mrNotes.  All
   // whitespace must be within one of these spans for this function to find the
   // right nodes.  And the span containing the children of this line must
   // immediately follow.  Assertions check this.
 
-  // |aEvent.target| will be one of the five spans.  Get the outer span.
+  // |aEvent.target| will be one of the spans.  Get the outer span.
   let outerSpan = aEvent.target.parentNode;
   assertClassListContains(outerSpan, "hasKids");
 
   // Toggle the '++'/'--' separator.
   let isExpansion;
   let sepSpan = outerSpan.childNodes[2];
   assertClassListContains(sepSpan, "mrSep");
   if (sepSpan.textContent === kHideKidsSep) {
@@ -1306,23 +1312,23 @@ function appendTreeElements(aPOuter, aT,
     } else {
       assert(!aT._hideKids, "leaf node with _hideKids set")
       sep = kNoKidsSep;
       d = aP;
     }
 
     appendMrValueSpan(d, tString, tIsInvalid);
     appendElementWithText(d, "span", "mrPerc", percText);
+    appendElementWithText(d, "span", "mrSep", sep);
 
     // We don't want to show '(nonheap)' on a tree like 'vsize/', since
     // the whole tree is non-heap.
     let kind = isExplicitTree ? aT._kind : undefined;
-    appendMrNameSpan(d, kind, sep, aT._description, aT._unsafeName,
+    appendMrNameSpan(d, kind, aT._description, aT._unsafeName,
                      tIsInvalid, aT._nMerged);
-    appendTextNode(d, "\n");
 
     // In non-verbose mode, invalid nodes can be hidden in collapsed sub-trees.
     // But it's good to always see them, so force this.
     if (!gVerbose && tIsInvalid) {
       expandPathToThisElement(d);
     }
 
     if (aT._kids) {
@@ -1446,19 +1452,19 @@ function appendOtherElements(aP, aReport
     let o = otherReports[i];
     let oIsInvalid = o.isInvalid();
     if (oIsInvalid) {
       gUnsafePathsWithInvalidValuesForThisProcess.push(o._unsafePath);
       reportAssertionFailure("Invalid value for " +
                              flipBackslashes(o._unsafePath));
     }
     appendMrValueSpan(pre, pad(o._asString, maxStringLength, ' '), oIsInvalid);
-    appendMrNameSpan(pre, KIND_OTHER, kNoKidsSep, o._description, o._unsafePath,
+    appendElementWithText(pre, "span", "mrSep", kNoKidsSep);
+    appendMrNameSpan(pre, KIND_OTHER, o._description, o._unsafePath,
                      oIsInvalid);
-    appendTextNode(pre, "\n");
   }
 
   appendTextNode(aP, "\n");  // gives nice spacing when we cut and paste
 }
 
 function appendSectionHeader(aP, aText)
 {
   appendElementWithText(aP, "h2", "", aText + "\n");