Mercurial > hg
changeset 44658:25436f83fb95
dagop: simplify dict/set reuse condition in subsetparentswalker
Prepares for fixing the calculation of p1/p2 sort keys.
With this change, there will be one more copying on merge&fork case. I think
the copying cost is negligible since we'll have to update each item in the
dict on merge/fork.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 26 Mar 2020 22:23:30 +0900 |
parents | 843418dc0b1b |
children | 67f757ed86e0 |
files | mercurial/dagop.py |
diffstat | 1 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dagop.py Sun Mar 29 14:22:07 2020 -0700 +++ b/mercurial/dagop.py Thu Mar 26 22:23:30 2020 +0900 @@ -449,12 +449,18 @@ # - one of the parents is not active, # - or descendants' parents are unresolved. if not bothparentsactive or unresolved or resolved: - if len(parentrevs) > 1: + if len(parentrevs) <= 1: + # can avoid copying the tracking pointer + parentpointers = [(unresolved, resolved)] + else: + parentpointers = [ + (unresolved, resolved), + (unresolved.copy(), resolved.copy()), + ] # 'rev' is a merge revision. increment the pending count # as the 'unresolved' dict will be duplicated. for r in unresolved: pendingcnt[r] += 1 - reusable = True # can we avoid copying the tracking pointer? for i, p in enumerate(parentrevs): assert p < rev heapq.heappush(tovisit, -p) @@ -462,6 +468,7 @@ # 'p' is a fork revision. concatenate tracking pointers # and decrement the pending count accordingly. knownunresolved, knownresolved = pointers[p] + unresolved, resolved = parentpointers[i] for r, c in unresolved.items(): c += [b'1', b'2'][i] if r in knownunresolved: @@ -475,11 +482,8 @@ # simply propagate the 'resolved' set as deduplicating # 'unresolved' here would be slightly complicated. knownresolved.update(resolved) - elif reusable: - pointers[p] = (unresolved, resolved) - reusable = False else: - pointers[p] = (unresolved.copy(), resolved.copy()) + pointers[p] = parentpointers[i] # then, populate the active parents directly and add the current # 'rev' to the tracking pointers of the inactive parents.