From 3d8c71a8cc2dbf333e97cb7d95880ddece4c781d Mon Sep 17 00:00:00 2001 From: Lucas Moscovicz Date: Tue, 4 Feb 2014 15:31:57 -0800 Subject: [PATCH] revset: added cache to lazysets This allows __contains__ to return faster when asked for same value twice. --- mercurial/revset.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mercurial/revset.py b/mercurial/revset.py index a223168982..e0694a943f 100644 --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -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