# HG changeset patch # User Pulkit Goyal # Date 2019-03-31 13:27:10 # Node ID f0def07fa82fb436e493a1beddfeb351ed9e4822 # Parent 29c22496dd973a568caae2953866b3d24eae3d6f branchmap: implement __contains__() We have good occurences of `if branch in branchmap()` in our code. If __contains__() is not implemented then it will use __iter__() to find whether the element exists or not which is not good. I am bit confused that whether I should move existing callers to hasbranch() or this patch is a good way. Differential Revision: https://phab.mercurial-scm.org/D6206 diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -182,6 +182,9 @@ class branchcache(object): def __getitem__(self, key): return self._entries[key] + def __contains__(self, key): + return key in self._entries + def iteritems(self): return self._entries.iteritems()