# HG changeset patch # User Pierre-Yves David # Date 2014-09-17 06:59:29 # Node ID 300e07582e9b9eda73f0d0456ca2f4b3c0dc2f8c # Parent abf4e98b8ff21c31d952fb883796fb771a2b43ac revset: add an optimised baseset.__contains__ (issue4371) The baseset class is based on a python list. This means that base.__contains__ was absolutely as crappy as list.__contains__. We now rely on __contains__ from the underlying set. This will avoid having to explicitly convert the baseset to a set (using baseset.set()) whenever one want fast membership test. Apparently there is already code that forgot to do such conversions since we observe a massive speedup in some test. revset #25: roots((0::) - (0::tip)) 0) wall 2.079454 comb 2.080000 user 2.080000 sys 0.000000 (best of 5) 1) wall 0.132970 comb 0.130000 user 0.130000 sys 0.000000 (best of 65) No regression is observed in benchmarks. This change improve the issue4371 back to acceptable situation (but are still slower than manual substraction) diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -2228,6 +2228,10 @@ class baseset(list): self._set = set(self) return self._set + @util.propertycache + def __contains__(self): + return self.set().__contains__ + def __sub__(self, other): """Returns a new object with the substraction of the two collections.