# HG changeset patch # User Pierre-Yves David # Date 1412358394 18000 # Node ID d34969a4b1a89058d9b36ab793a568d4f9866fc3 # Parent 5308f21c049e9d48db3f1c537fe4cacc9bcfbd8b 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. diff -r 5308f21c049e -r d34969a4b1a8 mercurial/revset.py --- 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