Skip to content

Commit 5c9c1be

Browse files
kovidgoyalgsnedders
authored andcommitted
Speed up unnecessarily slow and obtuse dict comparison
1 parent ad64b76 commit 5c9c1be

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

html5lib/html5parser.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,17 +1022,8 @@ def __init__(self, parser, tree):
10221022
self.endTagHandler.default = self.endTagOther
10231023

10241024
def isMatchingFormattingElement(self, node1, node2):
1025-
if node1.name != node2.name or node1.namespace != node2.namespace:
1026-
return False
1027-
elif len(node1.attributes) != len(node2.attributes):
1028-
return False
1029-
else:
1030-
attributes1 = sorted(node1.attributes.items())
1031-
attributes2 = sorted(node2.attributes.items())
1032-
for attr1, attr2 in zip(attributes1, attributes2):
1033-
if attr1 != attr2:
1034-
return False
1035-
return True
1025+
return (node1.name == node2.name and node1.namespace ==
1026+
node2.namespace and node1.attributes == node2.attributes)
10361027

10371028
# helper
10381029
def addFormattingElement(self, token):

0 commit comments

Comments
 (0)