changeset 20446:d258486604f4

revset: changed limit revset implementation to work with lazy revsets Performance benchmarking: $ time hg log -qr "first(branch(default))" 0:9117c6561b0b real 0m3.130s user 0m3.025s sys 0m0.074s $ time ./hg log -qr "first(branch(default))" 0:9117c6561b0b real 0m0.300s user 0m0.198s sys 0m0.069s
author Lucas Moscovicz <lmoscovicz@fb.com>
date Tue, 28 Jan 2014 16:19:30 -0800
parents 507261c0914f
children abb91b74f758
files mercurial/revset.py
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Wed Feb 05 16:12:03 2014 -0800
+++ b/mercurial/revset.py	Tue Jan 28 16:19:30 2014 -0800
@@ -944,8 +944,17 @@
         # i18n: "limit" is a keyword
         raise error.ParseError(_("limit expects a number"))
     ss = subset.set()
-    os = getset(repo, baseset(repo), l[0])[:lim]
-    return baseset([r for r in os if r in ss])
+    os = getset(repo, baseset(repo), l[0])
+    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 last(repo, subset, x):
     """``last(set, [n])``