baseset: explicitly track order of the baseset
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 03 Oct 2014 03:29:55 -0500
changeset 22829 36e09c25f870
parent 22828 966860f7a1a8
child 22830 1d1da8abe130
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.
mercurial/revset.py
--- a/mercurial/revset.py	Fri Oct 03 03:31:05 2014 -0500
+++ b/mercurial/revset.py	Fri Oct 03 03:29:55 2014 -0500
@@ -2372,10 +2372,13 @@
         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 @@
 
     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):