From patchwork Fri Aug 7 14:45:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [4, of, 4, V2] revset: make balanced addsets by orset() without using _combinesets() From: Yuya Nishihara X-Patchwork-Id: 10133 Message-Id: <97c73a40e9dc09c49d73.1438958747@mimosa> To: mercurial-devel@selenic.com Date: Fri, 07 Aug 2015 23:45:47 +0900 # HG changeset patch # User Yuya Nishihara # Date 1436068209 -32400 # Sun Jul 05 12:50:09 2015 +0900 # Node ID 97c73a40e9dc09c49d732fc79bffad38d520d01a # Parent fd7a0e50142b8d933be19414ac55b57dbd5e4612 revset: make balanced addsets by orset() without using _combinesets() As scmutil.revrange() was rewritten to not use _combinesets(), we no longer need _combinesets(). diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -406,8 +406,13 @@ def andset(repo, subset, x, y): return getset(repo, getset(repo, subset, x), y) def orset(repo, subset, *xs): - rs = [getset(repo, subset, x) for x in xs] - return _combinesets(rs) + assert xs + if len(xs) == 1: + return getset(repo, subset, xs[0]) + p = len(xs) // 2 + a = orset(repo, subset, *xs[:p]) + b = orset(repo, subset, *xs[p:]) + return a + b def notset(repo, subset, x): return subset - getset(repo, subset, x) @@ -3107,20 +3112,6 @@ class filteredset(abstractsmartset): def __repr__(self): return '<%s %r>' % (type(self).__name__, self._subset) -# this function will be removed, or merged to addset or orset, when -# - scmutil.revrange() can be rewritten to not combine calculated smartsets -# - or addset can handle more than two sets without balanced tree -def _combinesets(subsets): - """Create balanced tree of addsets representing union of given sets""" - if not subsets: - return baseset() - if len(subsets) == 1: - return subsets[0] - p = len(subsets) // 2 - xs = _combinesets(subsets[:p]) - ys = _combinesets(subsets[p:]) - return addset(xs, ys) - def _iterordered(ascending, iter1, iter2): """produce an ordered iteration from two iterators with the same order