[PATCH 11 of 13] revset: introduce a filterrevs function
Bryan O'Sullivan
bos at serpentine.com
Fri Jun 1 22:52:09 UTC 2012
# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1338591022 25200
# Node ID 770ce3ca6f9a788438347146d7f2a4d29ed5f21e
# Parent e071b98374034061df27dd2fbbea42f0ab8a1757
revset: introduce a filterrevs function
For large revsets, our pattern of always creating new lists is
expensive. This function tries to avoid unnecessary list duplication.
As an example, here's performance on a kernel repo with "hg
perfrevrange 2222::233333".
Before: 0.572 sec
After: 0.461 sec (20% better)
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -84,6 +84,21 @@ def revsubset(subset):
return set(subset)
return _revinterval(subset)
+def filterrevs(revs, subset, contig=False):
+ if not revs:
+ return revs
+ subset = revsubset(subset)
+ try:
+ if contig or isinstance(revs, (_revinterval, xrange)):
+ lo, hi = sorted((revs[0], revs[-1]))
+ else:
+ lo, hi = min(revs), max(revs)
+ if subset._start <= lo and subset._stop > hi:
+ return revs
+ except (AttributeError, TypeError, KeyError):
+ pass
+ return filter(subset.__contains__, revs)
+
def _revancestors(repo, revs, followfirst):
"""Like revlog.ancestors(), but supports followfirst."""
cut = followfirst and 1 or None
@@ -298,8 +313,7 @@ def dagrange(repo, subset, x, y):
if subset:
r = revsubset(repo)
xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
- s = revsubset(subset)
- return [r for r in xs if r in s]
+ return filterrevs(xs, subset, contig=True)
return []
def andset(repo, subset, x, y):
More information about the Mercurial-devel
mailing list