revlog: optimize deltachain
authorMatt Mackall <mpm@selenic.com>
Sun, 15 Aug 2010 23:13:56 -0500
changeset 11935 927ada259634
parent 11934 cf858e76e992
child 11936 5b559934d504
revlog: optimize deltachain
mercurial/revlog.py
--- a/mercurial/revlog.py	Tue Aug 10 22:28:52 2010 +0530
+++ b/mercurial/revlog.py	Sun Aug 15 23:13:56 2010 -0500
@@ -23,6 +23,8 @@
 _decompress = zlib.decompress
 _sha = util.sha1
 
+_cached, _uncached = 0, 0
+
 # revlog header flags
 REVLOGV0 = 0
 REVLOGNG = 1
@@ -1030,9 +1032,15 @@
         """return chain of revisions to construct a given revision"""
         chain = []
         check = False
-        while self.base(rev) != rev and rev != cache:
+        index = self.index
+        e = index[rev]
+        while rev != e[3] and rev != cache:
             chain.append(rev)
-            rev = self.deltaparent(rev)
+            if e[0] & REVIDX_PARENTDELTA:
+                rev = e[5]
+            else:
+                rev -= 1
+            e = index[rev]
         chain.reverse()
         if rev == cache:
             check = True
@@ -1068,7 +1076,13 @@
 
         # do we have useful data cached?
         if cache and self._cache:
+            global _cached
+            _cached += 1
             text = self._cache[2]
+        else:
+            global _uncached
+            _uncached += 1
+
 
         # drop cache to save memory
         self._cache = None