[PATCH 1 of 2] revset: changed lazyset __add__ implementation to work lazily
Lucas Moscovicz
lmoscovicz at fb.com
Mon Feb 24 17:58:34 CST 2014
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at 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
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:
More information about the Mercurial-devel
mailing list