diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-04-09 21:54:50 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-04-09 21:54:50 (GMT) |
commit | 0374a82f75b6929eb334d64e974926402e36c6a8 (patch) | |
tree | 22b1201edb1f7553cecef7e18bb61d6254819cdb /Lib/xml/dom | |
parent | ad95826c33ea378db2807a268363ccfbf0ea8273 (diff) | |
download | cpython-0374a82f75b6929eb334d64e974926402e36c6a8.zip cpython-0374a82f75b6929eb334d64e974926402e36c6a8.tar.gz cpython-0374a82f75b6929eb334d64e974926402e36c6a8.tar.bz2 |
Issue #2170: refactored xml.dom.minidom.normalize, increasing both
its clarity and its speed.
Diffstat (limited to 'Lib/xml/dom')
-rw-r--r-- | Lib/xml/dom/minidom.py | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index ad42947..b8bd451 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -177,34 +177,27 @@ class Node(xml.dom.Node): L = [] for child in self.childNodes: if child.nodeType == Node.TEXT_NODE: - data = child.data - if data and L and L[-1].nodeType == child.nodeType: + if not child.data: + # empty text node; discard + if L: + L[-1].nextSibling = child.nextSibling + if child.nextSibling: + child.nextSibling.previousSibling = child.previousSibling + child.unlink() + elif L and L[-1].nodeType == child.nodeType: # collapse text node node = L[-1] node.data = node.data + child.data node.nextSibling = child.nextSibling + if child.nextSibling: + child.nextSibling.previousSibling = node child.unlink() - elif data: - if L: - L[-1].nextSibling = child - child.previousSibling = L[-1] - else: - child.previousSibling = None - L.append(child) else: - # empty text node; discard - child.unlink() + L.append(child) else: - if L: - L[-1].nextSibling = child - child.previousSibling = L[-1] - else: - child.previousSibling = None L.append(child) if child.nodeType == Node.ELEMENT_NODE: child.normalize() - if L: - L[-1].nextSibling = None self.childNodes[:] = L def cloneNode(self, deep): |