Skip to content

Commit 124e975

Browse files
kovidgoyalgsnedders
authored andcommitted
Speed up unnecessarily slow and obtuse dict comparison
1 parent 1576515 commit 124e975

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
@@ -949,17 +949,8 @@ def __init__(self, parser, tree):
949949
self.endTagHandler.default = self.endTagOther
950950

951951
def isMatchingFormattingElement(self, node1, node2):
952-
if node1.name != node2.name or node1.namespace != node2.namespace:
953-
return False
954-
elif len(node1.attributes) != len(node2.attributes):
955-
return False
956-
else:
957-
attributes1 = sorted(node1.attributes.items())
958-
attributes2 = sorted(node2.attributes.items())
959-
for attr1, attr2 in zip(attributes1, attributes2):
960-
if attr1 != attr2:
961-
return False
962-
return True
952+
return (node1.name == node2.name and node1.namespace ==
953+
node2.namespace and node1.attributes == node2.attributes)
963954

964955
# helper
965956
def addFormattingElement(self, token):

0 commit comments

Comments
 (0)