From 29f0512e4cf4a4fb63b5e7c90ca3e53150a59743 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 26 Oct 2013 13:17:09 +0530 Subject: [PATCH] Speed up unnecessarily slow and obtuse dict comparison --- html5lib/html5parser.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/html5lib/html5parser.py b/html5lib/html5parser.py index 331b8fd7..ff886e89 100644 --- a/html5lib/html5parser.py +++ b/html5lib/html5parser.py @@ -1022,17 +1022,9 @@ def __init__(self, parser, tree): self.endTagHandler.default = self.endTagOther def isMatchingFormattingElement(self, node1, node2): - if node1.name != node2.name or node1.namespace != node2.namespace: - return False - elif len(node1.attributes) != len(node2.attributes): - return False - else: - attributes1 = sorted(node1.attributes.items()) - attributes2 = sorted(node2.attributes.items()) - for attr1, attr2 in zip(attributes1, attributes2): - if attr1 != attr2: - return False - return True + return (node1.name == node2.name and + node1.namespace == node2.namespace and + node1.attributes == node2.attributes) # helper def addFormattingElement(self, token):