Patchwork [1,of,2] revset: changed lazyset __add__ implementation to work lazily

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 24, 2014, 11:58 p.m.
Message ID <b243556d1edd940e65a0.1393286314@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3754/
State Accepted
Commit 2d52f37937b0f83077a4ffa8f381132329924c10
Headers show

Comments

Lucas Moscovicz - Feb. 24, 2014, 11:58 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1392310825 28800
#      Thu Feb 13 09:00:25 2014 -0800
# Node ID b243556d1edd940e65a0809e998b3507a0f337fb
# Parent  40d526f09065496c12125bf622b741ca40e8c7b4
revset: changed lazyset __add__ implementation to work lazily

Performance Benchmarking:

$ time hg log -qr "first(author(mpm) or branch(default))"
0:9117c6561b0b

real  0m3.875s
user  0m3.818s
sys 0m0.051s

$ time ./hg log -qr "first(author(mpm) or branch(default))"
0:9117c6561b0b

real  0m0.213s
user  0m0.174s
sys 0m0.038s

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2098,7 +2098,7 @@ 
     the subset and contains a function which tests for membership in the
     revset
     """
-    def __init__(self, subset, condition):
+    def __init__(self, subset, condition=lambda x: True):
         self._subset = subset
         self._condition = condition
         self._cache = {}
@@ -2122,8 +2122,14 @@ 
         return lazyset(self, lambda r: r not in x)
 
     def __add__(self, x):
-        l = baseset([r for r in self])
-        return l + baseset(x)
+        def iterates():
+            for r in self:
+                yield r
+            for r in x:
+                if r not in self:
+                    yield r
+
+        return lazyset(generatorset(iterates()))
 
     def __nonzero__(self):
         for r in self: