generatorset: make it possible to use gen as fastasc or fastdesc
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 03 Oct 2014 12:36:08 -0500
changeset 22755 f9a825b593be
parent 22754 1119e544cd2d
child 22756 5308f21c049e
generatorset: make it possible to use gen as fastasc or fastdesc We gain a parameter to inform that the generator is ascending or descending. If the generator is ordered, it is also used for the `fastasc` or `fastdesc` version. The _ascgeneratorset and _descgeneratorset class will be removed soon.
mercurial/revset.py
--- a/mercurial/revset.py	Fri Oct 03 03:19:00 2014 -0500
+++ b/mercurial/revset.py	Fri Oct 03 12:36:08 2014 -0500
@@ -2622,7 +2622,7 @@
     This class does not duck-type baseset and it's only supposed to be used
     internally
     """
-    def __init__(self, gen):
+    def __init__(self, gen, iterasc=None):
         """
         gen: a generator producing the values for the generatorset.
         """
@@ -2630,6 +2630,11 @@
         self._cache = {}
         self._genlist = baseset([])
         self._finished = False
+        if iterasc is not None:
+            if iterasc:
+                self.fastasc = self.__iter__
+            else:
+                self.fastdesc = self.__iter__
 
     def __nonzero__(self):
         for r in self: