Mercurial > hg
changeset 20534:4849f574aa24
revset: changed last implementation to use lazy classes
Instead of using getitem just reverse the revision list and get the first
'lim' elements. With classes like spanset which are easily reversible this
will work faster.
Performance Benchmarking:
$ time hg log -qr "last(all())"
...
real 0m0.569s
user 0m0.447s
sys 0m0.122s
$ time ./hg log -qr "last(all())"
...
real 0m0.215s
user 0m0.150s
sys 0m0.063s
author | Lucas Moscovicz <lmoscovicz@fb.com> |
---|---|
date | Wed, 19 Feb 2014 12:56:41 -0800 |
parents | 87e52e642562 |
children | 532b114a6e02 |
files | mercurial/revset.py |
diffstat | 1 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revset.py Wed Feb 19 16:46:47 2014 -0600 +++ b/mercurial/revset.py Wed Feb 19 12:56:41 2014 -0800 @@ -972,8 +972,18 @@ # i18n: "last" is a keyword raise error.ParseError(_("last expects a number")) ss = subset.set() - os = getset(repo, spanset(repo), l[0])[-lim:] - return baseset([r for r in os if r in ss]) + os = getset(repo, spanset(repo), l[0]) + os.reverse() + bs = baseset([]) + it = iter(os) + for x in xrange(lim): + try: + y = it.next() + if y in ss: + bs.append(y) + except (StopIteration): + break + return bs def maxrev(repo, subset, x): """``max(set)``