Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 666fdbb

Browse files
kovidgoyalgsnedders
authored andcommitted
Speed up unnecessarily slow and obtuse dict comparison
1 parent 9dca7d8 commit 666fdbb

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

942942
def isMatchingFormattingElement(self, node1, node2):
943-
if node1.name != node2.name or node1.namespace != node2.namespace:
944-
return False
945-
elif len(node1.attributes) != len(node2.attributes):
946-
return False
947-
else:
948-
attributes1 = sorted(node1.attributes.items())
949-
attributes2 = sorted(node2.attributes.items())
950-
for attr1, attr2 in zip(attributes1, attributes2):
951-
if attr1 != attr2:
952-
return False
953-
return True
943+
return (node1.name == node2.name and node1.namespace ==
944+
node2.namespace and node1.attributes == node2.attributes)
954945

955946
# helper
956947
def addFormattingElement(self, token):

0 commit comments

Comments
 (0)