Skip to content

Commit 587483d

Browse files
committed
Re-assign filteredEntityList as charStack grows.
There's no way entities that failed to match the prefix will match in future, so remove them. 6% perf gain parsing the spec.
1 parent f0e5df5 commit 587483d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

html5lib/tokenizer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ def consumeEntity(self, allowedChar=None, fromAttribute=False):
184184
def entitiesStartingWith(name):
185185
return [e for e in filteredEntityList if e.startswith(name)]
186186

187-
while (charStack[-1] is not EOF and
188-
entitiesStartingWith("".join(charStack))):
187+
while (charStack[-1] is not EOF):
188+
filteredEntityList = entitiesStartingWith(u"".join(charStack))
189+
if not filteredEntityList:
190+
break
189191
charStack.append(self.stream.char())
190192

191193
# At this point we have a string that starts with some characters

0 commit comments

Comments
 (0)