Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd85d895

Browse files
committed
Optimised entity lookup a bit. (Reduces tokenisation time by around 10% in some cases.)
--HG--extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%401157
1 parentbf696f4 commitd85d895

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

‎src/html5lib/tokenizer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
frominputstreamimportHTMLInputStream
1818

19+
# Group entities by their first character, for faster lookups
20+
entitiesByFirstChar= {}
21+
foreinentities:
22+
entitiesByFirstChar.setdefault(e[0], []).append(e)
23+
1924
classHTMLTokenizer(object):
2025
""" This class takes care of tokenizing HTML.
2126
@@ -224,8 +229,7 @@ def consumeEntity(self, allowedChar=None, fromAttribute=False):
224229
#
225230
# Consume characters and compare to these to a substring of the
226231
# entity names in the list until the substring no longer matches.
227-
filteredEntityList= [eforeinentitiesif \
228-
e.startswith(charStack[0])]
232+
filteredEntityList=entitiesByFirstChar.get(charStack[0], [])
229233

230234
defentitiesStartingWith(name):
231235
return [eforeinfilteredEntityListife.startswith(name)]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp