function sortTreeAndInsertAggregateNodes(aTotalBytes, aT)
{
  const kSignificanceThresholdPerc = 1;

  function isInsignificant(aT)
  {
    return !gVerbose &&
           (100 * aT._amount / aTotalBytes) < kSignificanceThresholdPerc;
  }

  if (!aT._kids) {
    return;
  }

  aT._kids.sort(TreeNode.compare);

  // If the first child is insignificant, they all are, and there's no point
  // creating an aggregate node that lacks siblings.  Just set the parent's
  // _hideKids property and process all children.
  if (isInsignificant(aT._kids[0])) {
    aT._hideKids = true;
    for (let i = 0; i < aT._kids.length; i++) {
      sortTreeAndInsertAggregateNodes(aTotalBytes, aT._kids[i]);
    }
    return;
  }

  // Look at all children except the last one.
  let i;
  for (i = 0; i < aT._kids.length - 1; i++) {
    if (isInsignificant(aT._kids[i])) {
      // This child is below the significance threshold.  If there are other
      // (smaller) children remaining, move them under an aggregate node.
      let i0 = i;
      let nAgg = aT._kids.length - i0;
      // Create an aggregate node.
      let aggT = new TreeNode("(" + nAgg + " tiny)");
      aggT._kids = [];
      let aggBytes = 0;
      for ( ; i < aT._kids.length; i++) {
        aggBytes += aT._kids[i]._amount;
        aggT._kids.push(aT._kids[i]);
      }
      aggT._hideKids = true;
      aggT._amount = aggBytes;
      aggT._description =
        nAgg + " sub-trees that are below the " + kSignificanceThresholdPerc +
        "% significance threshold.";
      aT._kids.splice(i0, nAgg, aggT);
      aT._kids.sort(TreeNode.compare);

      // Process the moved children.
      for (i = 0; i < aggT._kids.length; i++) {
        sortTreeAndInsertAggregateNodes(aTotalBytes, aggT._kids[i]);
      }
      return;
    }

    sortTreeAndInsertAggregateNodes(aTotalBytes, aT._kids[i]);
  }

  // The first n-1 children were significant.  Don't consider if the last child
  // is significant;  there's no point creating an aggregate node that only has
  // one child.  Just process it.
  sortTreeAndInsertAggregateNodes(aTotalBytes, aT._kids[i]);
}
/**
 * Sort all kid nodes from largest to smallest, and insert aggregate nodes
 * where appropriate.
 *
 * @param aTotalBytes
 *        The size of the tree's root node.
 * @param aT
 *        The tree.
 */
Sort all kid nodes from largest to smallest, and insert aggregate nodes
where appropriate.

@param aTotalBytes
The size of the tree's root node.
@param aT
The tree.
Sort all kid nodes from largest to smallest and insert aggregate nodes where appropriate . @param aTotalBytes The size of the tree ' s root node . @param aT The tree .
function sortTreeAndInsertAggregateNodes(aTotalBytes, aT)
{
  const kSignificanceThresholdPerc = 1;
  function isInsignificant(aT)
  {
    return !gVerbose &&
           (100 * aT._amount / aTotalBytes) < kSignificanceThresholdPerc;
  }
  if (!aT._kids) {
    return;
  }
  aT._kids.sort(TreeNode.compare);
  if (isInsignificant(aT._kids[0])) {
    aT._hideKids = true;
    for (let i = 0; i < aT._kids.length; i++) {
      sortTreeAndInsertAggregateNodes(aTotalBytes, aT._kids[i]);
    }
    return;
  }
  let i;
  for (i = 0; i < aT._kids.length - 1; i++) {
    if (isInsignificant(aT._kids[i])) {
      let i0 = i;
      let nAgg = aT._kids.length - i0;
      let aggT = new TreeNode("(" + nAgg + " tiny)");
      aggT._kids = [];
      let aggBytes = 0;
      for ( ; i < aT._kids.length; i++) {
        aggBytes += aT._kids[i]._amount;
        aggT._kids.push(aT._kids[i]);
      }
      aggT._hideKids = true;
      aggT._amount = aggBytes;
      aggT._description =
        nAgg + " sub-trees that are below the " + kSignificanceThresholdPerc +
        "% significance threshold.";
      aT._kids.splice(i0, nAgg, aggT);
      aT._kids.sort(TreeNode.compare);
      for (i = 0; i < aggT._kids.length; i++) {
        sortTreeAndInsertAggregateNodes(aTotalBytes, aggT._kids[i]);
      }
      return;
    }
    sortTreeAndInsertAggregateNodes(aTotalBytes, aT._kids[i]);
  }
  sortTreeAndInsertAggregateNodes(aTotalBytes, aT._kids[i]);
}
function sortTreeAndInsertAggregateNodes ( aTotalBytes , aT ) { const kSignificanceThresholdPerc = 1 ; function isInsignificant ( aT ) { return ! gVerbose && ( 100 * aT . _amount / aTotalBytes ) < kSignificanceThresholdPerc ; } if ( ! aT . _kids ) { return ; } aT . _kids . sort ( TreeNode . compare ) ; if ( isInsignificant ( aT . _kids [ 0 ] ) ) { aT . _hideKids = true ; for ( let i = 0 ; i < aT . _kids . length ; i ++ ) { sortTreeAndInsertAggregateNodes ( aTotalBytes , aT . _kids [ i ] ) ; } return ; } let i ; for ( i = 0 ; i < aT . _kids . length - 1 ; i ++ ) { if ( isInsignificant ( aT . _kids [ i ] ) ) { let i0 = i ; let nAgg = aT . _kids . length - i0 ; let aggT = new TreeNode ( "(" + nAgg + " tiny)" ) ; aggT . _kids = [ ] ; let aggBytes = 0 ; for ( ; i < aT . _kids . length ; i ++ ) { aggBytes += aT . _kids [ i ] . _amount ; aggT . _kids . push ( aT . _kids [ i ] ) ; } aggT . _hideKids = true ; aggT . _amount = aggBytes ; aggT . _description = nAgg + " sub-trees that are below the " + kSignificanceThresholdPerc + "% significance threshold." ; aT . _kids . splice ( i0 , nAgg , aggT ) ; aT . _kids . sort ( TreeNode . compare ) ; for ( i = 0 ; i < aggT . _kids . length ; i ++ ) { sortTreeAndInsertAggregateNodes ( aTotalBytes , aggT . _kids [ i ] ) ; } return ; } sortTreeAndInsertAggregateNodes ( aTotalBytes , aT . _kids [ i ] ) ; } sortTreeAndInsertAggregateNodes ( aTotalBytes , aT . _kids [ i ] ) ; }
Sort all kid nodes from largest to smallest, and insert aggregate nodes
 where appropriate.
Sort all kid nodes from largest to smallest and insert aggregate nodes where appropriate .
// If the first child is insignificant, they all are, and there's no point // creating an aggregate node that lacks siblings.  Just set the parent's // _hideKids property and process all children. // Look at all children except the last one. // This child is below the significance threshold.  If there are other // (smaller) children remaining, move them under an aggregate node. // Create an aggregate node. // Process the moved children. // The first n-1 children were significant.  Don't consider if the last child // is significant;  there's no point creating an aggregate node that only has // one child.  Just process it.