Patchwork [2,of,4] revset: changed limit revset implementation to work with lazy revsets

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 11, 2014, 6:50 p.m.
Message ID <6a54b66aa4d1acaa02bb.1392144651@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3569/
State Accepted
Commit d258486604f4c4be20a6ac1ecca1309cf3883cf2
Headers show

Comments

Lucas Moscovicz - Feb. 11, 2014, 6:50 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1390954770 28800
#      Tue Jan 28 16:19:30 2014 -0800
# Node ID 6a54b66aa4d1acaa02bb1292d4432cc37bdd6266
# Parent  44be4f156c4bc8f021bb303993d1311a0e4434c8
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

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -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])``