mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
revset: added cache to lazysets
This allows __contains__ to return faster when asked for same value twice.
This commit is contained in:
parent
b35d905ff6
commit
3d8c71a8cc
@ -2117,9 +2117,13 @@ class lazyset(object):
|
||||
def __init__(self, subset, condition):
|
||||
self._subset = subset
|
||||
self._condition = condition
|
||||
self._cache = {}
|
||||
|
||||
def __contains__(self, x):
|
||||
return x in self._subset and self._condition(x)
|
||||
c = self._cache
|
||||
if x not in c:
|
||||
c[x] = x in self._subset and self._condition(x)
|
||||
return c[x]
|
||||
|
||||
def __iter__(self):
|
||||
cond = self._condition
|
||||
|
Loading…
Reference in New Issue
Block a user