Skip to content

Commit 7702d80

Browse files
kovidgoyalgsnedders
authored andcommitted
Speed up parsing by not using element __bool__
1 parent 49f37d2 commit 7702d80

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

html5lib/html5parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ def startTagHeading(self, token):
10841084

10851085
def startTagA(self, token):
10861086
afeAElement = self.tree.elementInActiveFormattingElements("a")
1087-
if afeAElement:
1087+
if afeAElement is not False:
10881088
self.parser.parseError("unexpected-start-tag-implies-end-tag",
10891089
{"startName": "a", "endName": "a"})
10901090
self.endTagFormatting(impliedTagToken("a"))
@@ -1407,7 +1407,7 @@ def endTagFormatting(self, token):
14071407
# - has the same tag name as the token.
14081408
formattingElement = self.tree.elementInActiveFormattingElements(
14091409
token["name"])
1410-
if (not formattingElement or
1410+
if (formattingElement is False or
14111411
(formattingElement in self.tree.openElements and
14121412
not self.tree.elementInScope(formattingElement.name))):
14131413
# If there is no such node, then abort these steps
@@ -1509,7 +1509,7 @@ def endTagFormatting(self, token):
15091509
node = clone
15101510
# Step 9.9
15111511
# Remove lastNode from its parents, if any
1512-
if lastNode.parent:
1512+
if lastNode.parent is not None:
15131513
lastNode.parent.removeChild(lastNode)
15141514
node.appendChild(lastNode)
15151515
# Step 9.10
@@ -1519,7 +1519,7 @@ def endTagFormatting(self, token):
15191519
# Foster parent lastNode if commonAncestor is a
15201520
# table, tbody, tfoot, thead, or tr we need to foster
15211521
# parent the lastNode
1522-
if lastNode.parent:
1522+
if lastNode.parent is not None:
15231523
lastNode.parent.removeChild(lastNode)
15241524

15251525
if commonAncestor.name in frozenset(("table", "tbody", "tfoot", "thead", "tr")):

0 commit comments

Comments
 (0)