# HG changeset patch # User Pierre-Yves David # Date 1489263682 28800 # Node ID 62219171986348b606079dbd65a3ffea0d4083d1 # Parent 338d5600376c89aa7bc5eb4a1ebccd3a5e7cba47 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. diff -r 338d5600376c -r 622191719863 hgext3rd/evolve/obsdiscovery.py --- 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):