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
--- 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)``