381 # Set to None to indicate fast-path can be used next time, and to |
381 # Set to None to indicate fast-path can be used next time, and to |
382 # free up memory. |
382 # free up memory. |
383 self._containsiter = None |
383 self._containsiter = None |
384 return False |
384 return False |
385 |
385 |
386 class rustlazyancestors(lazyancestors): |
386 class rustlazyancestors(object): |
387 |
387 |
388 def __init__(self, index, revs, stoprev=0, inclusive=False): |
388 def __init__(self, index, revs, stoprev=0, inclusive=False): |
389 self._index = index |
389 self._index = index |
390 self._stoprev = stoprev |
390 self._stoprev = stoprev |
391 self._inclusive = inclusive |
391 self._inclusive = inclusive |
393 # it's done by rustlazyancestors constructor. |
393 # it's done by rustlazyancestors constructor. |
394 # we need to convert to a list, because our ruslazyancestors |
394 # we need to convert to a list, because our ruslazyancestors |
395 # constructor (from C code) doesn't understand anything else yet |
395 # constructor (from C code) doesn't understand anything else yet |
396 self._initrevs = initrevs = list(revs) |
396 self._initrevs = initrevs = list(revs) |
397 |
397 |
398 self._containsseen = set() |
|
399 self._containsiter = parsers.rustlazyancestors( |
398 self._containsiter = parsers.rustlazyancestors( |
400 index, initrevs, stoprev, inclusive) |
399 index, initrevs, stoprev, inclusive) |
|
400 |
|
401 def __nonzero__(self): |
|
402 """False if the set is empty, True otherwise. |
|
403 |
|
404 It's better to duplicate this essentially trivial method than |
|
405 to subclass lazyancestors |
|
406 """ |
|
407 try: |
|
408 next(iter(self)) |
|
409 return True |
|
410 except StopIteration: |
|
411 return False |
401 |
412 |
402 def __iter__(self): |
413 def __iter__(self): |
403 return parsers.rustlazyancestors(self._index, |
414 return parsers.rustlazyancestors(self._index, |
404 self._initrevs, |
415 self._initrevs, |
405 self._stoprev, |
416 self._stoprev, |
406 self._inclusive) |
417 self._inclusive) |
|
418 |
|
419 def __contains__(self, target): |
|
420 return target in self._containsiter |