stablerange: introduce caching for the full revision in a set
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Wed, 22 Mar 2017 20:18:01 +0100
changeset 2185 6b98ceed0626
parent 2184 3ec0be20e365
child 2186 57d58f27ffae
stablerange: introduce caching for the full revision in a set Such cache proved handy in the "per-range" class so we carry it along to the unified class. cf documentation for details.
hgext3rd/evolve/stablerange.py
--- a/hgext3rd/evolve/stablerange.py	Wed Mar 22 20:11:19 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Wed Mar 22 20:18:01 2017 +0100
@@ -162,6 +162,15 @@
         # the same for all ranges headed at the same merge. So we cache these
         # value to reuse them accross the same invocation.
         self._stablesortcache = {}
+        # if we already know all the revision that belong to a range, it is
+        # quite trivial to have the subrange "inherit" that knowledge. This
+        # cache is dedicated to hold the full list of revs inside a subrange
+        # when we happens to know it.
+        #
+        # For example. if we are slicing a range headed by a merge so will have
+        # the revision computed anyway, and passing that knowledge around might
+        # help to slice one of its subranges also containings a merge.
+        self._revsinrangecache = {}
 
     def warmup(self, repo, heads):
         """warm the cache up to 'heads'"""
@@ -219,13 +228,16 @@
         return value
 
     def revsfromrange(self, repo, rangeid):
-        # get all revs under heads in stable order
-        allrevs = self._stablesortcache.get(rangeid[0])
-        if allrevs is None:
-            allrevs = stablesort(repo, [rangeid[0]])
-            self._stablesortcache[rangeid[0]] = allrevs
-        # takes from index
-        revs = allrevs[rangeid[1]:]
+        revs = self._revsinrangecache.get(rangeid)
+        if revs is None:
+            # get all revs under heads in stable order
+            allrevs = self._stablesortcache.get(rangeid[0])
+            if allrevs is None:
+                allrevs = stablesort(repo, [rangeid[0]])
+                self._stablesortcache[rangeid[0]] = allrevs
+            # takes from index
+            revs = allrevs[rangeid[1]:]
+            self._revsinrangecache[rangeid] = revs
         # sanity checks
         assert len(revs) == self.rangelength(repo, rangeid)
         return revs
@@ -364,9 +376,11 @@
         self._head = head
         self._index = index
         if revs is not None:
+            self._repo.stablerange._revsinrangecache[self] = revs
+        # sanity checking
+        if revs is not None:
             length = self._repo.stablerange.rangelength(self._repo, self)
             assert len(revs) == length
-            self._revs = revs
         depth = self._repo.stablerange.depthrev(self._repo, self[0])
         assert index < depth, (head, index, depth, revs)