##// END OF EJS Templates
filteredset: drop explicit order management...
Pierre-Yves David -
r22862:9e5576f8 default
parent child Browse files
Show More
@@ -2299,12 +2299,7 class abstractsmartset(object):
2299 boolean.
2299 boolean.
2300
2300
2301 This is part of the mandatory API for smartset."""
2301 This is part of the mandatory API for smartset."""
2302 kwargs = {}
2302 return filteredset(self, condition)
2303 if self.isascending():
2304 kwargs['ascending'] = True
2305 elif self.isdescending():
2306 kwargs['ascending'] = False
2307 return filteredset(self, condition, **kwargs)
2308
2303
2309 class baseset(abstractsmartset):
2304 class baseset(abstractsmartset):
2310 """Basic data structure that represents a revset and contains the basic
2305 """Basic data structure that represents a revset and contains the basic
@@ -2406,7 +2401,7 class filteredset(abstractsmartset):
2406 the subset and contains a function which tests for membership in the
2401 the subset and contains a function which tests for membership in the
2407 revset
2402 revset
2408 """
2403 """
2409 def __init__(self, subset, condition=lambda x: True, ascending=None):
2404 def __init__(self, subset, condition=lambda x: True):
2410 """
2405 """
2411 condition: a function that decide whether a revision in the subset
2406 condition: a function that decide whether a revision in the subset
2412 belongs to the revset or not.
2407 belongs to the revset or not.
@@ -2414,9 +2409,6 class filteredset(abstractsmartset):
2414 self._subset = subset
2409 self._subset = subset
2415 self._condition = condition
2410 self._condition = condition
2416 self._cache = {}
2411 self._cache = {}
2417 if ascending is not None:
2418 ascending = bool(ascending)
2419 self._ascending = ascending
2420
2412
2421 def __contains__(self, x):
2413 def __contains__(self, x):
2422 c = self._cache
2414 c = self._cache
@@ -2464,27 +2456,19 class filteredset(abstractsmartset):
2464 return l[x]
2456 return l[x]
2465
2457
2466 def sort(self, reverse=False):
2458 def sort(self, reverse=False):
2467 if self._ascending is None:
2459 self._subset.sort(reverse=reverse)
2468 if not util.safehasattr(self._subset, 'sort'):
2469 self._subset = baseset(self._subset)
2470 self._subset.sort(reverse=reverse)
2471 self._ascending = not reverse
2472 elif bool(reverse) == self._ascending:
2473 self.reverse()
2474
2460
2475 def reverse(self):
2461 def reverse(self):
2476 self._subset.reverse()
2462 self._subset.reverse()
2477 if self._ascending is not None:
2478 self._ascending = not self._ascending
2479
2463
2480 def set(self):
2464 def set(self):
2481 return set([r for r in self])
2465 return set([r for r in self])
2482
2466
2483 def isascending(self):
2467 def isascending(self):
2484 return self._ascending is not None and self._ascending
2468 return self._subset.isascending()
2485
2469
2486 def isdescending(self):
2470 def isdescending(self):
2487 return self._ascending is not None and not self._ascending
2471 return self._subset.isdescending()
2488
2472
2489 def first(self):
2473 def first(self):
2490 for x in self:
2474 for x in self:
@@ -2493,11 +2477,10 class filteredset(abstractsmartset):
2493
2477
2494 def last(self):
2478 def last(self):
2495 it = None
2479 it = None
2496 if self._ascending is not None:
2480 if self._subset.isascending:
2497 if self._ascending:
2481 it = self.fastdesc
2498 it = self.fastdesc
2482 elif self._subset.isdescending:
2499 else:
2483 it = self.fastdesc
2500 it = self.fastasc
2501 if it is None:
2484 if it is None:
2502 # slowly consume everything. This needs improvement
2485 # slowly consume everything. This needs improvement
2503 it = lambda: reversed(list(self))
2486 it = lambda: reversed(list(self))
General Comments 0
You need to be logged in to leave comments. Login now