Patchwork [4,of,8] revset: added lazyset implementation to desc revset

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 11, 2014, 8:55 p.m.
Message ID <336524e10809d7898100.1392152119@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3578/
State Accepted
Commit a685d9870eb5623b8cd744f1790ff849f75643b5
Headers show

Comments

Lucas Moscovicz - Feb. 11, 2014, 8:55 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391125196 28800
#      Thu Jan 30 15:39:56 2014 -0800
# Node ID 336524e10809d78981001dda5465295b7d312109
# Parent  59c42d99bcfdd22636b43dd6beced0e194bf8bf8
revset: added lazyset implementation to desc revset

Performance benchmarking:

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

real  0m2.210s
user  0m2.158s
sys 0m0.049s

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

real  0m0.171s
user  0m0.131s
sys 0m0.035s

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -590,12 +590,12 @@ 
     """
     # i18n: "desc" is a keyword
     ds = encoding.lower(getstring(x, _("desc requires a string")))
-    l = []
-    for r in subset:
-        c = repo[r]
-        if ds in encoding.lower(c.description()):
-            l.append(r)
-    return baseset(l)
+
+    def matches(x):
+        c = repo[x]
+        return ds in encoding.lower(c.description())
+
+    return lazyset(subset, matches)
 
 def _descendants(repo, subset, x, followfirst=False):
     args = getset(repo, baseset(repo), x)