changeset 2090:622191719863

stablerange: adds some caching of the subranges The goal of subranges is to be as reusable as possible, so we cache the subrange relationship to take advantage of this.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sat, 11 Mar 2017 12:21:22 -0800
parents 338d5600376c
children fcb8db796576
files hgext3rd/evolve/obsdiscovery.py
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/obsdiscovery.py	Sat Mar 11 12:15:56 2017 -0800
+++ b/hgext3rd/evolve/obsdiscovery.py	Sat Mar 11 12:21:22 2017 -0800
@@ -579,6 +579,11 @@
         return result
 
     def subranges(self):
+        if not util.safehasattr(self._repo, '_subrangecache'):
+            self._repo._subrangecache = {}
+        cached = self._repo._subrangecache.get(self)
+        if cached is not None:
+            return cached
         if len(self) == 1:
             return []
         step = _hlp2(self.depth)
@@ -589,10 +594,13 @@
             step //= 2
         if self.index == standard_start:
             slicesize = _hlp2(len(self))
-            return self._slicesat(self.index + slicesize)
+            slicepoint = self.index + slicesize
         else:
             assert standard_start < self.depth
-            return self._slicesat(standard_start)
+            slicepoint = standard_start
+        result = self._slicesat(slicepoint)
+        self._repo._subrangecache[self] = result
+        return result
 
     @util.propertycache
     def obshash(self):