Patchwork [5,of,8] revset: added lazyset implementation to matching revset

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 11, 2014, 9:54 p.m.
Message ID <a8a52182a974dbc41acb.1392155683@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3592/
State Accepted
Commit 51890507c6b3be0b24afffaedd77a8ecd523ac9c
Headers show

Comments

Lucas Moscovicz - Feb. 11, 2014, 9:54 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391534085 28800
#      Tue Feb 04 09:14:45 2014 -0800
# Node ID a8a52182a974dbc41acb911ffd8feb7b1c77077b
# Parent  7a047e944f639aa3663f40e4f922ec9df9eb0c82
revset: added lazyset implementation to matching revset

Performance Benchmarking:

$ time hg log -qr "first(matching(0))"
0:9117c6561b0b

real  0m2.213s
user  0m2.149s
sys 0m0.055s

$ time ./hg log -qr "first(matching(0))"
0:9117c6561b0b

real  0m0.177s
user  0m0.137s
sys 0m0.038s

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1365,18 +1365,18 @@ 
     # is only one field to match)
     getinfo = lambda r: [f(r) for f in getfieldfuncs]
 
-    matches = set()
-    for rev in revs:
-        target = getinfo(rev)
-        for r in subset:
+    def matches(x):
+        for rev in revs:
+            target = getinfo(rev)
             match = True
             for n, f in enumerate(getfieldfuncs):
-                if target[n] != f(r):
+                if target[n] != f(x):
                     match = False
-                    break
             if match:
-                matches.add(r)
-    return baseset([r for r in subset if r in matches])
+                return True
+        return False
+
+    return lazyset(subset, matches)
 
 def reverse(repo, subset, x):
     """``reverse(set)``