mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
fixup_descriptors(): Change the way we look for descriptor nodes;
this takes 5 minutes off the conversion of the whole tree by reducing the number of tree-traversals from 14 to 1.
This commit is contained in:
parent
3d05b1a0ae
commit
3a7ff998ac
1 changed files with 15 additions and 4 deletions
|
|
@ -131,10 +131,21 @@ DESCRIPTOR_ELEMENTS = (
|
||||||
)
|
)
|
||||||
|
|
||||||
def fixup_descriptors(doc):
|
def fixup_descriptors(doc):
|
||||||
for tagName in DESCRIPTOR_ELEMENTS:
|
sections = find_all_elements(doc, "section")
|
||||||
nodes = find_all_elements(doc, tagName)
|
for section in sections:
|
||||||
for node in nodes:
|
find_and_fix_descriptors(doc, section)
|
||||||
rewrite_descriptor(doc, node)
|
|
||||||
|
|
||||||
|
def find_and_fix_descriptors(doc, container):
|
||||||
|
children = container.childNodes
|
||||||
|
for child in children:
|
||||||
|
if child.nodeType == xml.dom.core.ELEMENT:
|
||||||
|
tagName = child.tagName
|
||||||
|
if tagName in DESCRIPTOR_ELEMENTS:
|
||||||
|
rewrite_descriptor(doc, child)
|
||||||
|
elif tagName == "subsection":
|
||||||
|
find_and_fix_descriptors(doc, child)
|
||||||
|
|
||||||
|
|
||||||
def rewrite_descriptor(doc, descriptor):
|
def rewrite_descriptor(doc, descriptor):
|
||||||
#
|
#
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue