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

Commit66d242f

Browse files
committed
Optimised invalid-Unicode regexp. Cached match.end(). (Saves about 5-10% in the tokeniser.)
--HG--extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%401158
1 parentd85d895 commit66d242f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

‎src/html5lib/inputstream.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
asciiLettersBytes= [str(item)foriteminasciiLetters]
1212
asciiUppercaseBytes= [str(item)foriteminasciiUppercase]
1313

14-
invalid_unicode_re=re.compile(u"[\u0001-\u0008]|[\u000E-\u001F]|[\u007F-\u009F]|[\uD800-\uDFFF]|[\uFDD0-\uFDDF]|\uFFFE|\uFFFF|\U0001FFFE|\U0001FFFF|\U0002FFFE|\U0002FFFF|\U0003FFFE|\U0003FFFF|\U0004FFFE|\U0004FFFF|\U0005FFFE|\U0005FFFF|\U0006FFFE|\U0006FFFF|\U0007FFFE|\U0007FFFF|\U0008FFFE|\U0008FFFF|\U0009FFFE|\U0009FFFF|\U000AFFFE|\U000AFFFF|\U000BFFFE\U000BFFFF|\U000CFFFE|\U000CFFFF|\U000DFFFE|\U000DFFFF|\U000EFFFE|\U000EFFFF|\U000FFFFE|\U000FFFFF|\U0010FFFE|\U0010FFFF")
14+
invalid_unicode_re=re.compile(u"[\u0001-\u0008\u000E-\u001F\u007F-\u009F\uD800-\uDFFF\uFDD0-\uFDDF\uFFFE\uFFFF\U0001FFFE\U0001FFFF\U0002FFFE\U0002FFFF\U0003FFFE\U0003FFFF\U0004FFFE\U0004FFFF\U0005FFFE\U0005FFFF\U0006FFFE\U0006FFFF\U0007FFFE\U0007FFFF\U0008FFFE\U0008FFFF\U0009FFFE\U0009FFFF\U000AFFFE\U000AFFFF\U000BFFFE\U000BFFFF\U000CFFFE\U000CFFFF\U000DFFFE\U000DFFFF\U000EFFFE\U000EFFFF\U000FFFFE\U000FFFFF\U0010FFFE\U0010FFFF]")
1515

1616
# Cache for charsUntil()
1717
charsUntilRegEx= {}
@@ -320,9 +320,10 @@ def charsUntil(self, characters, opposite = False):
320320
# Find the longest matching prefix
321321
m=chars.match(self.chunk,self.chunkOffset)
322322
# If not everything matched, return everything up to the part that didn't match
323-
ifm.end()!=len(self.chunk):
324-
rv.append(self.chunk[self.chunkOffset:m.end()])
325-
self.chunkOffset=m.end()
323+
end=m.end()
324+
ifend!=len(self.chunk):
325+
rv.append(self.chunk[self.chunkOffset:end])
326+
self.chunkOffset=end
326327
break
327328
# If the whole chunk matched, use it all and read the next chunk
328329
rv.append(self.chunk[self.chunkOffset:])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp