Speed up parsing by not using element __bool__

This commit is contained in:
Kovid Goyal 2013-10-25 16:29:17 +05:30
parent 002895ff42
commit ea7930ee83

View File

@ -1084,7 +1084,7 @@ def getPhases(debug):
def startTagA(self, token): def startTagA(self, token):
afeAElement = self.tree.elementInActiveFormattingElements("a") afeAElement = self.tree.elementInActiveFormattingElements("a")
if afeAElement: if afeAElement is not False:
self.parser.parseError("unexpected-start-tag-implies-end-tag", self.parser.parseError("unexpected-start-tag-implies-end-tag",
{"startName": "a", "endName": "a"}) {"startName": "a", "endName": "a"})
self.endTagFormatting(impliedTagToken("a")) self.endTagFormatting(impliedTagToken("a"))
@ -1407,7 +1407,7 @@ def getPhases(debug):
# - has the same tag name as the token. # - has the same tag name as the token.
formattingElement = self.tree.elementInActiveFormattingElements( formattingElement = self.tree.elementInActiveFormattingElements(
token["name"]) token["name"])
if (not formattingElement or if (formattingElement is False or
(formattingElement in self.tree.openElements and (formattingElement in self.tree.openElements and
not self.tree.elementInScope(formattingElement.name))): not self.tree.elementInScope(formattingElement.name))):
# If there is no such node, then abort these steps # If there is no such node, then abort these steps
@ -1509,7 +1509,7 @@ def getPhases(debug):
node = clone node = clone
# Step 9.9 # Step 9.9
# Remove lastNode from its parents, if any # Remove lastNode from its parents, if any
if lastNode.parent: if lastNode.parent is not None:
lastNode.parent.removeChild(lastNode) lastNode.parent.removeChild(lastNode)
node.appendChild(lastNode) node.appendChild(lastNode)
# Step 9.10 # Step 9.10
@ -1519,7 +1519,7 @@ def getPhases(debug):
# Foster parent lastNode if commonAncestor is a # Foster parent lastNode if commonAncestor is a
# table, tbody, tfoot, thead, or tr we need to foster # table, tbody, tfoot, thead, or tr we need to foster
# parent the lastNode # parent the lastNode
if lastNode.parent: if lastNode.parent is not None:
lastNode.parent.removeChild(lastNode) lastNode.parent.removeChild(lastNode)
if commonAncestor.name in frozenset(("table", "tbody", "tfoot", "thead", "tr")): if commonAncestor.name in frozenset(("table", "tbody", "tfoot", "thead", "tr")):