# HG changeset patch # User Yuya Nishihara # Date 2018-01-19 12:39:11 # Node ID 29f57ce416edc29ee10d87507450f76ac9740f34 # Parent 693e3bcae19eff6dbd7333f8024cc955c1111e64 localrepo: micro-optimize __len__() to bypass repoview Since len(changelog) isn't overridden, we don't have to validate a cache of unfiltered changelog. $ python -m timeit -n 10000 \ -s 'from mercurial import hg, ui; repo = hg.repository(ui.ui());' \ 'len(repo)' orig) 10000 loops, best of 3: 32.1 usec per loop new) 10000 loops, best of 3: 1.79 usec per loop Spotted by Jordi GutiƩrrez Hermoso. diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -762,7 +762,9 @@ class localrepository(object): __bool__ = __nonzero__ def __len__(self): - return len(self.changelog) + # no need to pay the cost of repoview.changelog + unfi = self.unfiltered() + return len(unfi.changelog) def __iter__(self): return iter(self.changelog)