changeset 22757:d34969a4b1a8

generatorset: move membership testing on ordered gen to the main class We are phasing out the ordered version of the class to simplify the code.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 03 Oct 2014 12:46:34 -0500
parents 5308f21c049e
children 0fc52b01fb9e
files mercurial/revset.py
diffstat 1 files changed, 32 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Fri Oct 03 12:36:57 2014 -0500
+++ b/mercurial/revset.py	Fri Oct 03 12:46:34 2014 -0500
@@ -2633,8 +2633,10 @@
         if iterasc is not None:
             if iterasc:
                 self.fastasc = self.__iter__
+                self.__contains__ = self._asccontains
             else:
                 self.fastdesc = self.__iter__
+                self.__contains__ = self._desccontains
 
     def __nonzero__(self):
         for r in self:
@@ -2653,6 +2655,36 @@
         self._cache[x] = False
         return False
 
+    def _asccontains(self, x):
+        """version of contains optimised for ascending generator"""
+        if x in self._cache:
+            return self._cache[x]
+
+        # Use new values only, as existing values would be cached.
+        for l in self._consumegen():
+            if l == x:
+                return True
+            if l > x:
+                break
+
+        self._cache[x] = False
+        return False
+
+    def _desccontains(self, x):
+        """version of contains optimised for descending generator"""
+        if x in self._cache:
+            return self._cache[x]
+
+        # Use new values only, as existing values would be cached.
+        for l in self._consumegen():
+            if l == x:
+                return True
+            if l < x:
+                break
+
+        self._cache[x] = False
+        return False
+
     def __iter__(self):
         if self._finished:
             return iter(self._genlist)
@@ -2707,20 +2739,6 @@
     def __init__(self, gen):
         super(_ascgeneratorset, self).__init__(gen, iterasc=True)
 
-    def __contains__(self, x):
-        if x in self._cache:
-            return self._cache[x]
-
-        # Use new values only, as existing values would be cached.
-        for l in self._consumegen():
-            if l == x:
-                return True
-            if l > x:
-                break
-
-        self._cache[x] = False
-        return False
-
 class _descgeneratorset(_generatorset):
     """Wrap a generator of descending elements for lazy iteration
 
@@ -2734,20 +2752,6 @@
     def __init__(self, gen):
         super(_descgeneratorset, self).__init__(gen, iterasc=False)
 
-    def __contains__(self, x):
-        if x in self._cache:
-            return self._cache[x]
-
-        # Use new values only, as existing values would be cached.
-        for l in self._consumegen():
-            if l == x:
-                return True
-            if l < x:
-                break
-
-        self._cache[x] = False
-        return False
-
 def spanset(repo, start=None, end=None):
     """factory function to dispatch between fullreposet and actual spanset