changeset 20586:2d52f37937b0

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
author Lucas Moscovicz <lmoscovicz@fb.com>
date Thu, 13 Feb 2014 09:00:25 -0800
parents f3c8db3d6d66
children cb18fe3461b1
files mercurial/revset.py
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Tue Feb 25 10:32:54 2014 -0800
+++ b/mercurial/revset.py	Thu Feb 13 09:00:25 2014 -0800
@@ -2151,7 +2151,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 = {}
@@ -2175,8 +2175,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: