Patchwork revset: uncache filteredset.__contains__

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 9, 2015, 3:22 p.m.
Message ID <1d5f8bda8bb9d4d0e4e4.1441812157@mimosa>
Download mbox | patch
Permalink /patch/10435/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 9, 2015, 3:22 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1441425413 -32400
#      Sat Sep 05 12:56:53 2015 +0900
# Node ID 1d5f8bda8bb9d4d0e4e4b32eed6253e8b7907073
# Parent  29d29a82263f4380a73f05160a03887acf18806a
revset: uncache filteredset.__contains__

Since 96b6b3d78697, condition function returns a cached value, so there's
little benefit to cache __contains__.

No measurable difference found in contrib/base-revsets.txt.
Augie Fackler - Sept. 9, 2015, 3:34 p.m.
On Thu, Sep 10, 2015 at 12:22:37AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1441425413 -32400
> #      Sat Sep 05 12:56:53 2015 +0900
> # Node ID 1d5f8bda8bb9d4d0e4e4b32eed6253e8b7907073
> # Parent  29d29a82263f4380a73f05160a03887acf18806a
> revset: uncache filteredset.__contains__

queued, thanks

>
> Since 96b6b3d78697, condition function returns a cached value, so there's
> little benefit to cache __contains__.
>
> No measurable difference found in contrib/base-revsets.txt.
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -3077,14 +3077,9 @@ class filteredset(abstractsmartset):
>          """
>          self._subset = subset
>          self._condition = condition
> -        self._cache = {}
>
>      def __contains__(self, x):
> -        c = self._cache
> -        if x not in c:
> -            v = c[x] = x in self._subset and self._condition(x)
> -            return v
> -        return c[x]
> +        return x in self._subset and self._condition(x)
>
>      def __iter__(self):
>          return self._iterfilter(self._subset)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -3077,14 +3077,9 @@  class filteredset(abstractsmartset):
         """
         self._subset = subset
         self._condition = condition
-        self._cache = {}
 
     def __contains__(self, x):
-        c = self._cache
-        if x not in c:
-            v = c[x] = x in self._subset and self._condition(x)
-            return v
-        return c[x]
+        return x in self._subset and self._condition(x)
 
     def __iter__(self):
         return self._iterfilter(self._subset)