changeset 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 5840da876235
children dcd3bebf4786
files mercurial/revset.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sat Feb 15 19:12:53 2014 -0600
+++ b/mercurial/revset.py	Tue Feb 04 15:31:57 2014 -0800
@@ -2117,9 +2117,13 @@
     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