revlogio: speed up parsing
authorMatt Mackall <mpm@selenic.com>
Mon, 23 Jul 2007 20:44:08 -0500
changeset 4990 4491125c0f21
parent 4989 1aaed3d69772
child 4991 9c8c42bcf17a
revlogio: speed up parsing - precalcuate ending offset - pull some variables into local scope - separate inline and out of line code paths
mercurial/revlog.py
--- a/mercurial/revlog.py	Mon Jul 23 20:44:08 2007 -0500
+++ b/mercurial/revlog.py	Mon Jul 23 20:44:08 2007 -0500
@@ -360,19 +360,26 @@
         n = off = 0
         # if we're not using lazymap, always read the whole index
         data = fp.read()
-        l = len(data)
+        l = len(data) - s
+        unpack = struct.unpack
+        append = index.append
         if inline:
             cache = (0, data)
-        while off + s <= l:
-            e = struct.unpack(indexformatng, data[off:off + s])
-            index.append(e)
-            nodemap[e[7]] = n
-            n += 1
-            off += s
-            if inline:
+            while off <= l:
+                e = unpack(indexformatng, data[off:off + s])
+                nodemap[e[7]] = n
+                append(e)
+                n += 1
                 if e[1] < 0:
                     break
-                off += e[1]
+                off += e[1] + s
+        else:
+            while off <= l:
+                e = unpack(indexformatng, data[off:off + s])
+                nodemap[e[7]] = n
+                append(e)
+                n += 1
+                off += s
 
         e = list(index[0])
         type = gettype(e[0])