changeset 4975:8b7e480a7603

revlog: simplify the v1 immediate parser - read all the data at once (large files are handled by the lazy parser) - cache the entire file for inline revlogs - simplify looping
author Matt Mackall <mpm@selenic.com>
date Mon, 23 Jul 2007 20:44:08 -0500
parents a335345100ba
children 79c39cc9ff69
files mercurial/revlog.py
diffstat 1 files changed, 15 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Mon Jul 23 20:44:08 2007 -0500
+++ b/mercurial/revlog.py	Mon Jul 23 20:44:08 2007 -0500
@@ -333,44 +333,22 @@
         s = struct.calcsize(indexformatng)
         index = []
         nodemap =  {nullid: nullrev}
-        n = 0
-        leftover = None
-        while True:
-            if st:
-                data = fp.read(65536)
-            else:
-                # hack for httprangereader, it doesn't do partial reads well
-                data = fp.read()
-            if not data:
-                break
-            if n == 0 and inline:
-                # cache the first chunk
-                self.chunkcache = (0, data)
-            if leftover:
-                data = leftover + data
-                leftover = None
-            off = 0
-            l = len(data)
-            while off < l:
-                if l - off < s:
-                    leftover = data[off:]
+        n = off = 0
+        # if we're not using lazymap, always read the whole index
+        data = fp.read()
+        l = len(data)
+        if inline:
+            self.chunkcache = (0, data)
+        while off + s <= l:
+            e = struct.unpack(indexformatng, data[off:off + s])
+            index.append(e)
+            nodemap[e[-1]] = n
+            n += 1
+            off += s
+            if inline:
+                if e[1] < 0:
                     break
-                cur = data[off:off + s]
-                off += s
-                e = struct.unpack(indexformatng, cur)
-                index.append(e)
-                nodemap[e[-1]] = n
-                n += 1
-                if inline:
-                    if e[1] < 0:
-                        break
-                    off += e[1]
-                    if off > l:
-                        # some things don't seek well, just read it
-                        fp.read(off - l)
-                        break
-            if not st:
-                break
+                off += e[1]
 
         e = list(index[0])
         type = gettype(e[0])