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.
--- 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