Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revset.py @ 20643:7fc371d2e5a3
revset: added ordered generatorset classes with __contains__ method
They stop iterating as soon as they go past the value they are looking for,
so, for values not in the generator they return faster.
author | Lucas Moscovicz <lmoscovicz@fb.com> |
---|---|
date | Thu, 27 Feb 2014 17:27:03 -0800 |
parents | f2bb7ba59456 |
children | 379e89e4b079 |
comparison
equal
deleted
inserted
replaced
20642:0dc7a50345c2 | 20643:7fc371d2e5a3 |
---|---|
2294 yield item | 2294 yield item |
2295 | 2295 |
2296 def set(self): | 2296 def set(self): |
2297 return self | 2297 return self |
2298 | 2298 |
2299 class ascgeneratorset(generatorset): | |
2300 """ Same structure as generatorset but stops iterating after it goes past | |
2301 the value when asked for membership and the element is not contained | |
2302 """ | |
2303 def __contains__(self, x): | |
2304 if x in self._cache: | |
2305 return self._cache[x] | |
2306 | |
2307 for l in self: | |
2308 if l == x: | |
2309 return True | |
2310 if l > x: | |
2311 break | |
2312 | |
2313 self._cache[x] = False | |
2314 return False | |
2315 | |
2316 class descgeneratorset(generatorset): | |
2317 """ Same structure as generatorset but stops iterating after it goes past | |
2318 the value when asked for membership and the element is not contained | |
2319 """ | |
2320 def __contains__(self, x): | |
2321 if x in self._cache: | |
2322 return self._cache[x] | |
2323 | |
2324 for l in self: | |
2325 if l == x: | |
2326 return True | |
2327 if l < x: | |
2328 break | |
2329 | |
2330 self._cache[x] = False | |
2331 return False | |
2332 | |
2299 class spanset(object): | 2333 class spanset(object): |
2300 """Duck type for baseset class which represents a range of revisions and | 2334 """Duck type for baseset class which represents a range of revisions and |
2301 can work lazily and without having all the range in memory | 2335 can work lazily and without having all the range in memory |
2302 """ | 2336 """ |
2303 def __init__(self, repo, start=0, end=None): | 2337 def __init__(self, repo, start=0, end=None): |