[PATCH] revset: added cache to lazysets
Lucas Moscovicz
lmoscovicz at fb.com
Thu Feb 13 11:38: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 365b233e02ebf05d1b91e48d12f28f0c5ddd990c
# Parent cf2a8a38d2665eff5787de8c12d4d23031493ba6
revset: added cache to lazysets
This allows __contains__ to return faster when asked for same value twice.
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2100,9 +2100,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
More information about the Mercurial-devel
mailing list