Patchwork [3,of,4] revset: added lazyset implementation to limit revset

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 6, 2014, 6:02 p.m.
Message ID <da06f86f6560bcd74ea6.1391709761@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3495/
State Deferred
Headers show

Comments

Lucas Moscovicz - Feb. 6, 2014, 6:02 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1390954770 28800
#      Tue Jan 28 16:19:30 2014 -0800
# Node ID da06f86f6560bcd74ea6740c3858a6a482a5e281
# Parent  464c7b677edfed6f7d00199a08c8dd7e32e72bca
revset: added lazyset implementation to limit revset

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
@@ -962,8 +962,17 @@ 
     if isinstance(subset, lazyset):
         subset = baseset(subset)
     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])``