generatorset: get list-based fast iterations after the generator is consumed
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 03 Oct 2014 21:01:30 -0700
changeset 22798 586d7058ea48
parent 22797 61ecabeeadb3
child 22799 bafa371d7af3
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.
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