comparison mercurial/revset.py @ 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 0d4be103c734
children cb18fe3461b1
comparison
equal deleted inserted replaced
20585:f3c8db3d6d66 20586:2d52f37937b0
2149 class lazyset(object): 2149 class lazyset(object):
2150 """Duck type for baseset class which iterates lazily over the revisions in 2150 """Duck type for baseset class which iterates lazily over the revisions in
2151 the subset and contains a function which tests for membership in the 2151 the subset and contains a function which tests for membership in the
2152 revset 2152 revset
2153 """ 2153 """
2154 def __init__(self, subset, condition): 2154 def __init__(self, subset, condition=lambda x: True):
2155 self._subset = subset 2155 self._subset = subset
2156 self._condition = condition 2156 self._condition = condition
2157 self._cache = {} 2157 self._cache = {}
2158 2158
2159 def __contains__(self, x): 2159 def __contains__(self, x):
2173 2173
2174 def __sub__(self, x): 2174 def __sub__(self, x):
2175 return lazyset(self, lambda r: r not in x) 2175 return lazyset(self, lambda r: r not in x)
2176 2176
2177 def __add__(self, x): 2177 def __add__(self, x):
2178 l = baseset([r for r in self]) 2178 def iterates():
2179 return l + baseset(x) 2179 for r in self:
2180 yield r
2181 for r in x:
2182 if r not in self:
2183 yield r
2184
2185 return lazyset(generatorset(iterates()))
2180 2186
2181 def __nonzero__(self): 2187 def __nonzero__(self):
2182 for r in self: 2188 for r in self:
2183 return True 2189 return True
2184 return False 2190 return False