[PATCH 2 of 2] revset: changed spanset __add__ implementation to work lazily

Lucas Moscovicz lmoscovicz at fb.com
Mon Feb 24 23:58:35 UTC 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1392311896 28800
#      Thu Feb 13 09:18:16 2014 -0800
# Node ID 62bd70d853a96bb33c451ac40ca5c6cf1394986a
# Parent  b243556d1edd940e65a0809e998b3507a0f337fb
revset: changed spanset __add__ implementation to work lazily

$ time hg log -qr "first(0:tip or draft())"
...

real  0m1.032s
user  0m0.841s
sys 0m0.179s

$ time ./hg log -qr "first(0:tip or draft())"
...

real  0m0.378s
user  0m0.291s
sys 0m0.085s

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2258,8 +2258,14 @@
         return lazyset(self, lambda r: r not in x)
 
     def __add__(self, x):
-        l = baseset(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 __len__(self):
         if not self._hiddenrevs:



More information about the Mercurial-devel mailing list