# HG changeset patch
# User Matt Mackall <mpm@selenic.com>
# Date 2007-07-24 01:44:08
# Node ID 4491125c0f2142b3b4be15e2320ac51c4586daf5
# Parent  1aaed3d69772c3df60971d79d323bf6301f8686a

revlogio: speed up parsing

- precalcuate ending offset
- pull some variables into local scope
- separate inline and out of line code paths

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -360,19 +360,26 @@ class revlogio(object):
         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])