[PATCH] revset: added negative cache to lazysets

Lucas Moscovicz lmoscovicz at fb.com
Wed Feb 12 20:34:09 CST 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1391556717 28800
#      Tue Feb 04 15:31:57 2014 -0800
# Node ID 7d11b638a9cf4e99213e73a704a497da5a1e2d2b
# Parent  cf2a8a38d2665eff5787de8c12d4d23031493ba6
revset: added negative cache to lazysets

The idea of this is to be able to answer faster when something is not
contained in the lazyset instead of having to calculate it again.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2100,9 +2100,15 @@
     def __init__(self, subset, condition):
         self._subset = subset
         self._condition = condition
+        self._ncache = set()
 
     def __contains__(self, x):
-        return x in self._subset and self._condition(x)
+        if x in self._ncache:
+            return False
+        c =  x in self._subset and self._condition(x)
+        if not c:
+            self._ncache.add(x)
+        return c
 
     def __iter__(self):
         cond = self._condition


More information about the Mercurial-devel mailing list