[PATCH 1 of 2] revlog: add __contains__ for fast membership test

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Feb 5 06:53:54 CST 2015



On 02/04/2015 04:29 PM, Gregory Szorc wrote:
> diff --git a/mercurial/changelog.py b/mercurial/changelog.py
>
>     --- a/mercurial/changelog.py
>     +++ b/mercurial/changelog.py
>     @@ -143,6 +143,11 @@ class changelog(revlog.revlog):
>                   if i not in self.filteredrevs:
>                       return self.node(i)
>
>     +    def __contains__(self, rev):
>     +        """filtered version of revlog.__contains__"""
>     +        return (revlog.revlog.__contains__(self, rev)
>     +                and rev not in self.filteredrevs)
>     +
>
>
> What you've implemented here is changelog.hasunfilteredrev(). I'm not
> convinced __contains__ should be implemented:

__contains__ should be implemented because otherwise, "rev in changelog" 
is still valid but ultra slow (uses __iter__).

> a) to only accept numeric revisions (what about nodes)

  The current semantic accepts revs only and I'm fine with that.

> b) to only operate on unfiltered revs

No it does not? It looks at `self.filteredrevs`.

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list