Patchwork [1,of,4] revset: reduce dict lookup in lazyset.__contains__

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 19, 2014, 8:42 p.m.
Message ID <a38a9240a0c57afe2f49.1411159329@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5882/
State Superseded
Headers show

Comments

Pierre-Yves David - Sept. 19, 2014, 8:42 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1398462684 25200
#      Fri Apr 25 14:51:24 2014 -0700
# Node ID a38a9240a0c57afe2f4939f41a63382ef76b92fc
# Parent  f007f2faf06eda9ab45e2d44e280ef6cf8c410fc
revset: reduce dict lookup in lazyset.__contains__

Avoid an extra dict lookup when we have to compute the value.  No visible impact
but this shaving the yack a few extra nanometer.
Pierre-Yves David - Sept. 20, 2014, 1 a.m.
On 09/19/2014 01:42 PM, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1398462684 25200
> #      Fri Apr 25 14:51:24 2014 -0700
> # Node ID a38a9240a0c57afe2f4939f41a63382ef76b92fc
> # Parent  f007f2faf06eda9ab45e2d44e280ef6cf8c410fc
> revset: reduce dict lookup in lazyset.__contains__

This seems a duplicate of another series. This was sent by mistake 
instead of a series about "revert"

Please disregard this version.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2334,11 +2334,12 @@  class lazyset(object):
         return max(self)
 
     def __contains__(self, x):
         c = self._cache
         if x not in c:
-            c[x] = x in self._subset and self._condition(x)
+            v = c[x] = x in self._subset and self._condition(x)
+            return v
         return c[x]
 
     def __iter__(self):
         cond = self._condition
         for x in self._subset: