changeset 3302:f890d27df766

stablerange: cache known subrange at the stablerangecached level That way, the 'stablerange_mergepoint' class also benefit from it.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 10 Dec 2017 12:12:12 +0100
parents 5c45df0c8e36
children 318c938be80d
files hgext3rd/evolve/stablerange.py
diffstat 1 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablerange.py	Sun Dec 17 22:05:34 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Sun Dec 10 12:12:12 2017 +0100
@@ -298,6 +298,11 @@
 
     __metaclass__ = abc.ABCMeta
 
+    def __init__(self):
+        # cache the standard stable subranges or a range
+        self._subrangescache = {}
+        super(stablerangecached, self).__init__()
+
     def depthrev(self, repo, rev):
         return repo.depthcache.get(rev)
 
@@ -306,6 +311,26 @@
         headrev, index = rangeid[0], rangeid[1]
         return self.depthrev(repo, headrev) - index
 
+    def subranges(self, repo, rangeid):
+        cached = self._getsub(rangeid)
+        if cached is not None:
+            return cached
+        value = self._subranges(repo, rangeid)
+        self._setsub(rangeid, value)
+        return value
+
+    def _getsub(self, rev):
+        """utility function used to access the subranges cache
+
+        This mostly exist to help the on disk persistence"""
+        return self._subrangescache.get(rev)
+
+    def _setsub(self, rev, value):
+        """utility function used to set the subranges cache
+
+        This mostly exist to help the on disk persistence."""
+        self._subrangescache[rev] = value
+
 class stablerange_mergepoint(stablerangecached, stablerangebasic):
     """Stablerange implementation using 'mergepoint' based sorting
     """
@@ -350,7 +375,7 @@
             relevant_parent = min(p1, p2, key=tiebreaker)
         return relevant_parent
 
-    def subranges(self, repo, rangeid):
+    def _subranges(self, repo, rangeid):
         headrev, initial_index = rangeid
         # size 1 range can't be sliced
         if self.rangelength(repo, rangeid) == 1:
@@ -437,8 +462,6 @@
         # The point up to which we have data in cache
         self._tiprev = None
         self._tipnode = None
-        # cache the standard stable subranges or a range
-        self._subrangescache = {}
         # To slices merge, we need to walk their descendant in reverse stable
         # sort order. For now we perform a full stable sort their descendant
         # and then use the relevant top most part. This order is going to be
@@ -455,6 +478,7 @@
         # computed from that point to compute some of the subranges from the
         # merge.
         self._inheritancecache = {}
+        super(stablerange, self).__init__()
 
     def warmup(self, repo, upto=None):
         """warm the cache up"""