changeset 2184:3ec0be20e365

stablerange: add a cache for stablesort ordering This will be very handy for merge, cf inline documentation for details.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Wed, 22 Mar 2017 20:11:19 +0100
parents 3c2992afee71
children 6b98ceed0626
files hgext3rd/evolve/stablerange.py
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablerange.py	Wed Mar 22 20:05:21 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py	Wed Mar 22 20:11:19 2017 +0100
@@ -156,6 +156,13 @@
         self._depthcache = {}
         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
+        # the same for all ranges headed at the same merge. So we cache these
+        # value to reuse them accross the same invocation.
+        self._stablesortcache = {}
+
     def warmup(self, repo, heads):
         """warm the cache up to 'heads'"""
         for r in repo.revs("::%ld", heads):
@@ -213,7 +220,10 @@
 
     def revsfromrange(self, repo, rangeid):
         # get all revs under heads in stable order
-        allrevs = stablesort(repo, [rangeid[0]])
+        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]:]
         # sanity checks