| Index: tools/metrics/histograms/pretty_print.py
|
| diff --git a/tools/metrics/histograms/pretty_print.py b/tools/metrics/histograms/pretty_print.py
|
| index 00e9ff5d386d1fa3c7e3f0e845f814cad04da233..d9e0327952beb283a0ef484229851544735a09e8 100755
|
| --- a/tools/metrics/histograms/pretty_print.py
|
| +++ b/tools/metrics/histograms/pretty_print.py
|
| @@ -80,14 +80,27 @@ def TransformByAlphabetizing(node):
|
| # Put subnodes in a list of node,key pairs to allow for custom sorting.
|
| subtag, key_function = ALPHABETIZATION_RULES[node.tagName]
|
| subnodes = []
|
| - last_key = -1
|
| + sort_key = -1
|
| + pending_node_indices = []
|
| for c in node.childNodes:
|
| if (c.nodeType == xml.dom.minidom.Node.ELEMENT_NODE and
|
| c.tagName == subtag):
|
| - last_key = key_function(c)
|
| - # Subnodes that we don't want to rearrange use the last node's key,
|
| - # so they stay in the same relative position.
|
| - subnodes.append( (c, last_key) )
|
| + sort_key = key_function(c)
|
| + # Replace sort keys for delayed nodes.
|
| + for idx in pending_node_indices:
|
| + subnodes[idx][1] = sort_key
|
| + pending_node_indices = []
|
| + else:
|
| + # Subnodes that we don't want to rearrange use the next node's key,
|
| + # so they stay in the same relative position.
|
| + # Therefore we delay setting key until the next node is found.
|
| + pending_node_indices.append(len(subnodes))
|
| +
|
| + subnodes.append( [c, sort_key] )
|
| +
|
| + # Use last sort key for trailing unknown nodes.
|
| + for idx in pending_node_indices:
|
| + subnodes[idx][1] = sort_key
|
|
|
| # Sort the subnode list.
|
| subnodes.sort(key=lambda pair: pair[1])
|
|
|