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

Commit2310bd8

Browse files
gsneddersjgraham
authored andcommitted
Make scanning for meta encoding much quicker
Previously, this code tried to match everything with stringsbeginning with "<"; now we jump forward to each "<" and comparethere. This also alters the jumpTo implementation to avoidcomputing a (perhaps long) slice, making repeated calls O(n^2).
1 parent4b8cabf commit2310bd8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

‎html5lib/_inputstream.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -668,15 +668,11 @@ def matchBytes(self, bytes):
668668
defjumpTo(self,bytes):
669669
"""Look for the next sequence of bytes matching a given sequence. If
670670
a match is found advance the position to the last byte of the match"""
671-
newPosition=self[self.position:].find(bytes)
672-
ifnewPosition>-1:
673-
# XXX: This is ugly, but I can't see a nicer way to fix this.
674-
ifself._position==-1:
675-
self._position=0
676-
self._position+= (newPosition+len(bytes)-1)
677-
returnTrue
678-
else:
671+
try:
672+
self._position=self.index(bytes,self.position)+len(bytes)-1
673+
exceptValueError:
679674
raiseStopIteration
675+
returnTrue
680676

681677

682678
classEncodingParser(object):
@@ -697,6 +693,10 @@ def getEncoding(self):
697693
(b"<",self.handlePossibleStartTag))
698694
for_inself.data:
699695
keepParsing=True
696+
try:
697+
self.data.jumpTo(b"<")
698+
exceptStopIteration:
699+
break
700700
forkey,methodinmethodDispatch:
701701
ifself.data.matchBytes(key):
702702
try:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp