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 is much
slower but this shaves the yak a few extra nanometers.
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.
--- a/mercurial/revset.py Tue Sep 16 23:10:39 2014 -0700
+++ b/mercurial/revset.py Fri Apr 25 17:53:58 2014 -0700
@@ -2793,9 +2793,11 @@
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: