Commit f2d92284 authored by Pawel Pluciennik's avatar Pawel Pluciennik Committed by Commit Bot

Improve performance of generating histograms.xml

This CL implements IterElementsWithTag to avoid not needed recursion.

On local machine it saved around 1s (from 7.6s to 6.6s).

Bug: 1016281
Change-Id: I0fea65892bc52574fd4e6fd3fd2455ae3ec646e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872052
Commit-Queue: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709564}
parent 4ac8b448
......@@ -303,9 +303,10 @@ def ExpandHistogramsOWNERS(histograms):
Error: Raised if the OWNERS file with the given path does not exist.
"""
email_pattern = re.compile(_EMAIL_PATTERN)
iter_matches = extract_histograms.IterElementsWithTag
for histogram in histograms.getElementsByTagName('histogram'):
owners = histogram.getElementsByTagName('owner')
for histogram in iter_matches(histograms, 'histogram'):
owners = [owner for owner in iter_matches(histogram, 'owner', 1)]
# owner is a DOM Element with a single child, which is a DOM Text Node.
emails_with_dom_elements = set([
......@@ -316,12 +317,10 @@ def ExpandHistogramsOWNERS(histograms):
# component is a DOM Element with a single child, which is a DOM Text Node.
components_with_dom_elements = set([
extract_histograms.NormalizeString(component.childNodes[0].data)
for component in histogram.getElementsByTagName('component')])
for component in iter_matches(histogram, 'component', 1)])
for index in range(len(owners)):
owner = owners[index]
for index, owner in enumerate(owners):
owner_text = owner.childNodes[0].data
name = histogram.getAttribute('name')
if _IsEmailOrPlaceholder(index == 0, owner_text, name):
continue
......
......@@ -6,9 +6,11 @@
"""A script to merge multiple source xml files into a single histograms.xml."""
import argparse
import expand_owners
import xml.dom.minidom
import expand_owners
import extract_histograms
def GetElementsByTagName(trees, tag):
"""Gets all elements with the specified tag from a set of DOM trees.
......@@ -19,7 +21,8 @@ def GetElementsByTagName(trees, tag):
Returns:
A list of DOM nodes with the specified tag.
"""
return [e for t in trees for e in t.getElementsByTagName(tag)]
iterator = extract_histograms.IterElementsWithTag
return list(e for t in trees for e in iterator(t, tag, 2))
def MakeNodeWithChildren(doc, tag, children):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment