Patchwork changelog: inline revlog.__contains__ in case it is used in hot loop

login
register
mail settings
Submitter Yuya Nishihara
Date April 8, 2015, 1:09 p.m.
Message ID <8931fb2127b03c349947.1428498598@mimosa>
Download mbox | patch
Permalink /patch/8561/
State Accepted
Headers show

Comments

Yuya Nishihara - April 8, 2015, 1:09 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1428154259 -32400
#      Sat Apr 04 22:30:59 2015 +0900
# Node ID 8931fb2127b03c349947c25997841dd6cd8e519a
# Parent  b9a2b5018024213aeacd235426740152991066e1
changelog: inline revlog.__contains__ in case it is used in hot loop

Currently __contains__ is called only by "rev()" revset, but "x in cl" is a
function that is likely to be used in hot loop. revlog.__contains__ is simple
enough to duplicate to changelog, so just inline it.
Matt Mackall - April 8, 2015, 7:14 p.m.
On Wed, 2015-04-08 at 22:09 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1428154259 -32400
> #      Sat Apr 04 22:30:59 2015 +0900
> # Node ID 8931fb2127b03c349947c25997841dd6cd8e519a
> # Parent  b9a2b5018024213aeacd235426740152991066e1
> changelog: inline revlog.__contains__ in case it is used in hot loop

Queued for default, thanks.

Patch

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -145,7 +145,7 @@  class changelog(revlog.revlog):
 
     def __contains__(self, rev):
         """filtered version of revlog.__contains__"""
-        return (revlog.revlog.__contains__(self, rev)
+        return (0 <= rev < len(self)
                 and rev not in self.filteredrevs)
 
     def __iter__(self):