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

Commited1c27f

Browse files
committed
Use a deque for the character queue. Patch by shawn.hsiao
--HG--extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%401010
1 parentd548509 commited1c27f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

‎src/html5lib/inputstream.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
fromconstantsimportEOF,spaceCharacters,asciiLetters,asciiUppercase
66
fromconstantsimportencodings
77
fromutilsimportMethodDispatcher
8+
fromcollectionsimportdeque
89

10+
try:
11+
fromcollectionsimportdeque
12+
exceptImportError:
13+
fromutilsimportdeque
14+
915
classHTMLInputStream(object):
1016
"""Provides a unicode stream of characters to the HTMLTokenizer.
1117
@@ -55,7 +61,7 @@ def __init__(self, source, encoding=None, parseMeta=True, chardet=True):
5561
self.dataStream=codecs.getreader(self.charEncoding)(self.rawStream,
5662
'replace')
5763

58-
self.queue=[]
64+
self.queue=deque([])
5965
self.errors= []
6066

6167
self.line=self.col=0
@@ -212,7 +218,7 @@ def char(self):
212218
ifnotself.queue:
213219
returnEOF
214220

215-
char=self.queue.pop(0)
221+
char=self.queue.popleft()
216222

217223
# update position in stream
218224
ifchar=='\n':
@@ -277,8 +283,7 @@ def charsUntil(self, characters, opposite = False):
277283
else:
278284
self.col+=1
279285

280-
rv=u"".join(self.queue[:i])
281-
self.queue=self.queue[i:]
286+
rv=u"".join([self.queue.popleft()forcinrange(i) ])
282287

283288
#Calculate where we now are in the stream
284289
#One possible optimisation would be to store all read characters and
@@ -313,7 +318,9 @@ def charsUntil(self, characters, opposite = False):
313318

314319
defunget(self,chars):
315320
ifchars:
316-
self.queue=list(chars)+self.queue
321+
l=list(chars)
322+
l.reverse()
323+
self.queue.extendleft(l)
317324
#Alter the current line, col position
318325
forcinchars[::-1]:
319326
ifc=='\n':

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp