Skip to content

Commit fec1bb5

Browse files
committed
Move assignment of the constant listElementMap out of the hot elementInScope.
This gains 6% parsing the spec.
1 parent 587483d commit fec1bb5

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

html5lib/treebuilders/_base.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
# from "leaking" into tables, object elements, and marquees.
1212
Marker = None
1313

14+
listElementsMap = {
15+
None:(frozenset(scopingElements), False),
16+
"button":(frozenset(scopingElements | set([(namespaces["html"], "button")])), False),
17+
"list":(frozenset(scopingElements | set([(namespaces["html"], "ol"),
18+
(namespaces["html"], "ul")])), False),
19+
"table":(frozenset([(namespaces["html"], "html"),
20+
(namespaces["html"], "table")]), False),
21+
"select":(frozenset([(namespaces["html"], "optgroup"),
22+
(namespaces["html"], "option")]), True)
23+
}
24+
25+
1426
class Node(object):
1527
def __init__(self, name):
1628
"""Node representing an item in the tree.
@@ -157,16 +169,6 @@ def elementInScope(self, target, variant=None):
157169
#match any node with that name
158170
exactNode = hasattr(target, "nameTuple")
159171

160-
listElementsMap = {
161-
None:(scopingElements, False),
162-
"button":(scopingElements | set([(namespaces["html"], "button")]), False),
163-
"list":(scopingElements | set([(namespaces["html"], "ol"),
164-
(namespaces["html"], "ul")]), False),
165-
"table":(set([(namespaces["html"], "html"),
166-
(namespaces["html"], "table")]), False),
167-
"select":(set([(namespaces["html"], "optgroup"),
168-
(namespaces["html"], "option")]), True)
169-
}
170172
listElements, invert = listElementsMap[variant]
171173

172174
for node in reversed(self.openElements):

0 commit comments

Comments
 (0)