changeset 22826:4ffb327e4719

baseset: implement a fastasc and fastdesc Baseset contains already-computed revisions. It is considered "cheap" to do operations on an already-computed set. So we add attributes to hold version of the list in ascending and descending order and use them for `fastasc` and `fastdesc`. Having distinct lists is important to provide correct iteration in all cases. Altering a python list will impact an iterator connected to it. eg: not preserving order at iterator creation time >>> l = [0, 1] >>> i = iter(l) >>> l.reverse() >>> list(i) [1, 0] eg: corrupting in progress iteration >>> l = [0, 1] >>> i = iter(l) >>> i.next() 0 >>> l.reverse() >>> i.next() 0
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 03 Oct 2014 03:19:23 -0500
parents 0e8bb81b58b9
children c1107cb21df2
files mercurial/revset.py
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Mon Oct 06 11:03:30 2014 -0700
+++ b/mercurial/revset.py	Fri Oct 03 03:19:23 2014 -0500
@@ -2332,6 +2332,18 @@
         self._list = data
         self._set = None
 
+    @util.propertycache
+    def _asclist(self):
+        asclist = self._list[:]
+        asclist.sort()
+        return asclist
+
+    def fastasc(self):
+        return iter(self._asclist)
+
+    def fastdesc(self):
+        return reversed(self._asclist)
+
     def set(self):
         """Returns a set or a smartset containing all the elements.