Patchwork revset: added cache to lazysets

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 13, 2014, 5:38 p.m.
Message ID <365b233e02ebf05d1b91.1392313089@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3635/
State Accepted
Commit 659b8d8ddf197873acdde797e0f551b7b1dcf440
Headers show

Comments

Lucas Moscovicz - Feb. 13, 2014, 5:38 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@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.
Matt Mackall - Feb. 16, 2014, 1:16 a.m.
On Thu, 2014-02-13 at 09:38 -0800, Lucas Moscovicz wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1391556717 28800
> #      Tue Feb 04 15:31:57 2014 -0800
> # Node ID 365b233e02ebf05d1b91e48d12f28f0c5ddd990c
> # Parent  cf2a8a38d2665eff5787de8c12d4d23031493ba6
> revset: added cache to lazysets

Queued for default, thanks.

Patch

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