Skip to content

Commit 29f0512

Browse files
kovidgoyalgsnedders
authored andcommitted
Speed up unnecessarily slow and obtuse dict comparison
1 parent 2812e44 commit 29f0512

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

html5lib/html5parser.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -1022,17 +1022,9 @@ 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
1026+
node1.namespace == node2.namespace and
1027+
node1.attributes == node2.attributes)
10361028

10371029
# helper
10381030
def addFormattingElement(self, token):

0 commit comments

Comments
 (0)