comparison mercurial/revlog.py @ 116:e484cd5ec282

Only use lazy indexing for big indices and avoid the overhead of the lazy index in the small index case.
author mpm@selenic.com
date Fri, 20 May 2005 17:35:20 -0800
parents 39b438eeb25a
children 2ac722ad1a9d
comparison
equal deleted inserted replaced
115:39b438eeb25a 116:e484cd5ec282
122 def __init__(self, opener, indexfile, datafile): 122 def __init__(self, opener, indexfile, datafile):
123 self.indexfile = indexfile 123 self.indexfile = indexfile
124 self.datafile = datafile 124 self.datafile = datafile
125 self.opener = opener 125 self.opener = opener
126 self.cache = None 126 self.cache = None
127 # read the whole index for now, handle on-demand later 127
128 try: 128 try:
129 i = self.opener(self.indexfile).read() 129 i = self.opener(self.indexfile).read()
130 except IOError: 130 except IOError:
131 i = "" 131 i = ""
132 parser = lazyparser(i) 132
133 self.index = lazyindex(parser) 133 if len(i) > 10000:
134 self.nodemap = lazymap(parser) 134 # big index, let's parse it on demand
135 parser = lazyparser(i)
136 self.index = lazyindex(parser)
137 self.nodemap = lazymap(parser)
138 else:
139 s = struct.calcsize(indexformat)
140 l = len(i) / s
141 self.index = [None] * l
142 m = [None] * l
143
144 n = 0
145 for f in xrange(0, len(i), s):
146 # offset, size, base, linkrev, p1, p2, nodeid
147 e = struct.unpack(indexformat, i[f:f + s])
148 m[n] = (e[6], n)
149 self.index[n] = e
150 n += 1
151
152 self.nodemap = dict(m)
153 self.nodemap[nullid] = -1
154
135 155
136 def tip(self): return self.node(len(self.index) - 1) 156 def tip(self): return self.node(len(self.index) - 1)
137 def count(self): return len(self.index) 157 def count(self): return len(self.index)
138 def node(self, rev): return (rev < 0) and nullid or self.index[rev][6] 158 def node(self, rev): return (rev < 0) and nullid or self.index[rev][6]
139 def rev(self, node): return self.nodemap[node] 159 def rev(self, node): return self.nodemap[node]