Patchwork [1,of,5] revset: do less lookup during spanset.__contains__

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 19, 2014, 10:33 p.m.
Message ID <f007f2faf06eda9ab45e.1411166034@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5885/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 19, 2014, 10:33 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1398473638 25200
#      Fri Apr 25 17:53:58 2014 -0700
# Node ID f007f2faf06eda9ab45e2d44e280ef6cf8c410fc
# Parent  e282c07bac1a5627920f53bd8b233a55ce42d05d
revset: do less lookup during spanset.__contains__

Attribute lookup is slow in python. So this version is going to be a bit
faster. This does not have a visible impact since the rest of the stack if most
slower but this shave the yack a few extra nanometer.

Moreover the new version is more readable so it worth doing this change for code
quality purpose.

This optimisation was approved by a core python dev.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2774,13 +2774,15 @@  class spanset(_orderedsetmixin):
         else:
             for r in iterrange:
                 yield r
 
     def __contains__(self, rev):
-        return (((self._end < rev <= self._start)
-                  or (self._start <= rev < self._end))
-                and not (self._hiddenrevs and rev in self._hiddenrevs))
+        start = self._start
+        end = self._end
+        hidden = self._hiddenrevs
+        return (((end < rev <= start) or (start <= rev and rev < end))
+                and not (hidden and rev in hidden))
 
     def __nonzero__(self):
         for r in self:
             return True
         return False