# HG changeset patch # User Pierre-Yves David # Date 1412395290 25200 # Node ID 586d7058ea480907fa0f8473ba070b9088ce21d6 # Parent 61ecabeeadb3a9998efb0a55ab38a8ea7a59b048 generatorset: get list-based fast iterations after the generator is consumed When all revisions are known, we shortcut most of the class logic to use list iteration instead. The cost of the sort is expected to be non-significant. The list creation and sorting could be done lazily in the future. We have to copy the list to not break existing iterator created before we finished consuming the generator. diff -r 61ecabeeadb3 -r 586d7058ea48 mercurial/revset.py --- a/mercurial/revset.py Fri Oct 03 20:48:28 2014 -0700 +++ b/mercurial/revset.py Fri Oct 03 21:01:30 2014 -0700 @@ -2621,6 +2621,7 @@ gen: a generator producing the values for the generatorset. """ self._gen = gen + self._asclist = None self._cache = {} self._genlist = [] self._finished = False @@ -2712,7 +2713,13 @@ cache[item] = True genlist(item) yield item - self._finished = True + if not self._finished: + self._finished = True + asc = self._genlist[:] + asc.sort() + self._asclist = asc + self.fastasc = asc.__iter__ + self.fastdesc = asc.__reversed__ def set(self): return self