comparison mercurial/revset.py @ 22864:96b6b3d78697

revset: cache most conditions used in `filter` Except when stated otherwise, the condition used in `smartset.filter` will be cached. A new argument has been introduced to disable that behavior. We use it for filters created from `and` and `sub` operations. This gives massive performance boosts for revsets with expensive conditions. revset: branch(stable) or branch(default) before) wall 4.329070 comb 4.320000 user 4.310000 sys 0.010000 (best of 3) after) wall 2.356451 comb 2.360000 user 2.330000 sys 0.030000 (best of 4) revset: author(mpm) or author(lmoscovicz) before) wall 4.434719 comb 4.440000 user 4.440000 sys 0.000000 (best of 3) after) wall 2.321720 comb 2.320000 user 2.320000 sys 0.000000 (best of 4)
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 09 Oct 2014 22:57:52 -0700
parents a1a02b516cca
children 09951bedbf35
comparison
equal deleted inserted replaced
22863:a1a02b516cca 22864:96b6b3d78697
2275 2275
2276 def __and__(self, other): 2276 def __and__(self, other):
2277 """Returns a new object with the intersection of the two collections. 2277 """Returns a new object with the intersection of the two collections.
2278 2278
2279 This is part of the mandatory API for smartset.""" 2279 This is part of the mandatory API for smartset."""
2280 return self.filter(other.__contains__) 2280 return self.filter(other.__contains__, cache=False)
2281 2281
2282 def __add__(self, other): 2282 def __add__(self, other):
2283 """Returns a new object with the union of the two collections. 2283 """Returns a new object with the union of the two collections.
2284 2284
2285 This is part of the mandatory API for smartset.""" 2285 This is part of the mandatory API for smartset."""
2288 def __sub__(self, other): 2288 def __sub__(self, other):
2289 """Returns a new object with the substraction of the two collections. 2289 """Returns a new object with the substraction of the two collections.
2290 2290
2291 This is part of the mandatory API for smartset.""" 2291 This is part of the mandatory API for smartset."""
2292 c = other.__contains__ 2292 c = other.__contains__
2293 return self.filter(lambda r: not c(r)) 2293 return self.filter(lambda r: not c(r), cache=False)
2294 2294
2295 def filter(self, condition): 2295 def filter(self, condition, cache=True):
2296 """Returns this smartset filtered by condition as a new smartset. 2296 """Returns this smartset filtered by condition as a new smartset.
2297 2297
2298 `condition` is a callable which takes a revision number and returns a 2298 `condition` is a callable which takes a revision number and returns a
2299 boolean. 2299 boolean.
2300 2300
2301 This is part of the mandatory API for smartset.""" 2301 This is part of the mandatory API for smartset."""
2302 # builtin cannot be cached. but do not needs to
2303 if cache and util.safehasattr(condition, 'func_code'):
2304 condition = util.cachefunc(condition)
2302 return filteredset(self, condition) 2305 return filteredset(self, condition)
2303 2306
2304 class baseset(abstractsmartset): 2307 class baseset(abstractsmartset):
2305 """Basic data structure that represents a revset and contains the basic 2308 """Basic data structure that represents a revset and contains the basic
2306 operation that it should be able to perform. 2309 operation that it should be able to perform.