Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 20512:659b8d8ddf19
revset: added cache to lazysets
This allows __contains__ to return faster when asked for same value twice.
author | Lucas Moscovicz <lmoscovicz@fb.com> |
---|---|
date | Tue, 04 Feb 2014 15:31:57 -0800 |
parents | 2efd608473fb |
children | 1850a7f5fb66 |
comparison
equal
deleted
inserted
replaced
20511:5840da876235 | 20512:659b8d8ddf19 |
---|---|
2115 revset | 2115 revset |
2116 """ | 2116 """ |
2117 def __init__(self, subset, condition): | 2117 def __init__(self, subset, condition): |
2118 self._subset = subset | 2118 self._subset = subset |
2119 self._condition = condition | 2119 self._condition = condition |
2120 self._cache = {} | |
2120 | 2121 |
2121 def __contains__(self, x): | 2122 def __contains__(self, x): |
2122 return x in self._subset and self._condition(x) | 2123 c = self._cache |
2124 if x not in c: | |
2125 c[x] = x in self._subset and self._condition(x) | |
2126 return c[x] | |
2123 | 2127 |
2124 def __iter__(self): | 2128 def __iter__(self): |
2125 cond = self._condition | 2129 cond = self._condition |
2126 for x in self._subset: | 2130 for x in self._subset: |
2127 if cond(x): | 2131 if cond(x): |