mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
baseset: explicitly track order of the baseset
A baseset starts without an explicit order. But as soon as a sort is requested, we simply register that the baseset has an order and use the ordered version of the list to behave accordingly. We will want to properly record the order at creation time in the future. This would unlock more optimisation and avoid some sorting.
This commit is contained in:
parent
cf7077b249
commit
eb55591aca
@ -2372,10 +2372,13 @@ class baseset(abstractsmartset):
|
||||
return bool(self._list)
|
||||
|
||||
def sort(self, reverse=False):
|
||||
self._list.sort(reverse=reverse)
|
||||
self._ascending = not bool(reverse)
|
||||
|
||||
def reverse(self):
|
||||
self._list.reverse()
|
||||
if self._ascending is None:
|
||||
self._list.reverse()
|
||||
else:
|
||||
self._ascending = not self._ascending
|
||||
|
||||
def __len__(self):
|
||||
return len(self._list)
|
||||
@ -2421,12 +2424,22 @@ class baseset(abstractsmartset):
|
||||
|
||||
def first(self):
|
||||
if self:
|
||||
return self._list[0]
|
||||
if self._ascending is None:
|
||||
return self._list[0]
|
||||
elif self._ascending:
|
||||
return self._asclist[0]
|
||||
else:
|
||||
return self._asclist[-1]
|
||||
return None
|
||||
|
||||
def last(self):
|
||||
if self:
|
||||
return self._list[-1]
|
||||
if self._ascending is None:
|
||||
return self._list[-1]
|
||||
elif self._ascending:
|
||||
return self._asclist[-1]
|
||||
else:
|
||||
return self._asclist[0]
|
||||
return None
|
||||
|
||||
class filteredset(abstractsmartset):
|
||||
|
Loading…
Reference in New Issue
Block a user