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.
This commit is contained in:
Pierre-Yves David 2014-04-25 17:53:58 -07:00
parent f89da734dc
commit e291b5bdba

View File

@ -2793,9 +2793,11 @@ class _spanset(_orderedsetmixin):
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: