1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
=== modified file 'cvs2svn_rcsparse/default.py'
--- cvs2svn_rcsparse/default.py 2007-11-18 23:05:32 +0000
+++ cvs2svn_rcsparse/default.py 2010-01-23 10:21:47 +0000
@@ -19,7 +19,7 @@
import common
class _TokenStream:
- token_term = string.whitespace + ';:'
+ token_term = frozenset(string.whitespace + ';:')
# the algorithm is about the same speed for any CHUNK_SIZE chosen.
# grab a good-sized chunk, but not too large to overwhelm memory.
@@ -44,15 +44,17 @@
# out more complex solutions.
buf = self.buf
+ lbuf = len(buf)
idx = self.idx
while 1:
- if idx == len(buf):
+ if idx == lbuf:
buf = self.rcsfile.read(self.CHUNK_SIZE)
if buf == '':
# signal EOF by returning None as the token
del self.buf # so we fail if get() is called again
return None
+ lbuf = len(buf)
idx = 0
if buf[idx] not in string.whitespace:
@@ -60,7 +62,7 @@
idx = idx + 1
- if buf[idx] == ';' or buf[idx] == ':':
+ if buf[idx] in ';:':
self.buf = buf
self.idx = idx + 1
return buf[idx]
@@ -70,17 +72,18 @@
token = ''
while 1:
# find token characters in the current buffer
- while end < len(buf) and buf[end] not in self.token_term:
+ while end < lbuf and buf[end] not in self.token_term:
end = end + 1
token = token + buf[idx:end]
- if end < len(buf):
+ if end < lbuf:
# we stopped before the end, so we have a full token
idx = end
break
# we stopped at the end of the buffer, so we may have a partial token
buf = self.rcsfile.read(self.CHUNK_SIZE)
+ lbuf = len(buf)
idx = end = 0
self.buf = buf
@@ -94,22 +97,24 @@
chunks = [ ]
while 1:
- if idx == len(buf):
+ if idx == lbuf:
idx = 0
buf = self.rcsfile.read(self.CHUNK_SIZE)
if buf == '':
raise RuntimeError, 'EOF'
+ lbuf = len(buf)
i = string.find(buf, '@', idx)
if i == -1:
chunks.append(buf[idx:])
- idx = len(buf)
+ idx = lbuf
continue
- if i == len(buf) - 1:
+ if i == lbuf - 1:
chunks.append(buf[idx:i])
idx = 0
buf = '@' + self.rcsfile.read(self.CHUNK_SIZE)
if buf == '@':
raise RuntimeError, 'EOF'
+ lbuf = len(buf)
continue
if buf[i + 1] == '@':
chunks.append(buf[idx:i+1])
@@ -121,7 +126,7 @@
self.buf = buf
self.idx = i + 1
- return string.join(chunks, '')
+ return ''.join(chunks)
# _get = get
# def get(self):
|