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

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 24, 2014, 11:58 p.m.
Message ID <62bd70d853a96bb33c45.1393286315@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3755/
State Accepted
Commit cb18fe3461b15611f7f7bebcbd09e0d2d1e7a46e
Headers show

Comments

Lucas Moscovicz - Feb. 24, 2014, 11:58 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@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
Matt Mackall - Feb. 27, 2014, 10 p.m.
On Mon, 2014-02-24 at 15:58 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@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

These are queued for default, thanks.

Patch

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: