commit: increase perf by avoiding unnecessary filteredrevs check
When commiting to a repo with lots of history (>400000 changesets)
the filteredrevs check (added with
5c89e7fa5bc2) in changelog.py
takes a bit of time even if the filteredrevs set is empty. Skipping
the check in that case shaves 0.36 seconds off a 2.14 second commit.
A 17% gain.
--- a/mercurial/changelog.py Thu Nov 15 11:27:30 2012 -0600
+++ b/mercurial/changelog.py Fri Nov 16 15:39:12 2012 -0800
@@ -134,9 +134,15 @@
def __iter__(self):
"""filtered version of revlog.__iter__"""
- for i in xrange(len(self)):
- if i not in self.filteredrevs:
- yield i
+ if len(self.filteredrevs) == 0:
+ return revlog.revlog.__iter__(self)
+
+ def filterediter():
+ for i in xrange(len(self)):
+ if i not in self.filteredrevs:
+ yield i
+
+ return filterediter()
def revs(self, start=0, stop=None):
"""filtered version of revlog.revs"""
--- a/mercurial/revlog.py Thu Nov 15 11:27:30 2012 -0600
+++ b/mercurial/revlog.py Fri Nov 16 15:39:12 2012 -0800
@@ -254,8 +254,7 @@
def __len__(self):
return len(self.index) - 1
def __iter__(self):
- for i in xrange(len(self)):
- yield i
+ return iter(xrange(len(self)))
def revs(self, start=0, stop=None):
"""iterate over all rev in this revlog (from start to stop)"""
if stop is None: