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..a53a33445bb4324508d38eae28f431e3aad572a4 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 |
+ unset_node_keys_indexes = [] |
Ilya Sherman
2014/09/02 22:29:48
nit: Perhaps something like "pending_node_indices"
Alexander Alekseev
2014/09/02 23:53:28
Done.
|
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 unset_node_keys_indexes: |
+ subnodes[idx][1] = sort_key |
+ unset_node_keys_indexes = [] |
+ 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 before next node is found. |
Ilya Sherman
2014/09/02 22:29:48
nit: "before next node is found" -> "until the nex
Alexander Alekseev
2014/09/02 23:53:28
Done.
|
+ unset_node_keys_indexes.append(len(subnodes)) |
+ |
+ subnodes.append( [c, sort_key] ) |
+ |
+ # Use last sort key for trailing unknown nodes. |
+ for idx in unset_node_keys_indexes: |
+ subnodes[idx][1] = sort_key |
# Sort the subnode list. |
subnodes.sort(key=lambda pair: pair[1]) |