Skip to content
Snippets Groups Projects
Commit 828dc8db authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

revlog: add __contains__ for fast membership test

Because revlog implements __iter__, "rev in revlog" works but does silly O(n)
lookup unexpectedly. So it seems good to add fast version of __contains__.

This allows "rev in repo.changelog" in the next patch.
parent e1dbe0b2
No related branches found
No related tags found
No related merge requests found
......@@ -143,6 +143,11 @@
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)
def __iter__(self):
"""filtered version of revlog.__iter__"""
if len(self.filteredrevs) == 0:
......
......@@ -277,6 +277,8 @@
def tip(self):
return self.node(len(self.index) - 2)
def __contains__(self, rev):
return 0 <= rev < len(self)
def __len__(self):
return len(self.index) - 1
def __iter__(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment