# HG changeset patch # User Pierre-Yves David # Date 1412324363 18000 # Node ID 4ffb327e471981c4370087857768557e293c8264 # Parent 0e8bb81b58b9b29969b40db1d78b8b675fdb2805 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 diff -r 0e8bb81b58b9 -r 4ffb327e4719 mercurial/revset.py --- 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.