# HG changeset patch # User Yuya Nishihara # Date 2018-09-10 12:54:40 # Node ID b9ee9c2e10ddd911cdb0a0a408823045c25e6e75 # Parent fd9029d36c41e77002ca9647827c11b86f896d8c ancestor: unroll loop of parents in _lazyancestorsiter() This change itself isn't major performance win, but it helps optimizing the visit loop for contiguous chains. See the next patch. diff --git a/mercurial/ancestor.py b/mercurial/ancestor.py --- a/mercurial/ancestor.py +++ b/mercurial/ancestor.py @@ -274,20 +274,26 @@ def _lazyancestorsiter(parentrevs, initr visit = [] heapq.heapify(visit) for r in initrevs: - for parent in parentrevs(r): - if parent not in seen: - schedule(visit, -parent) - see(parent) + p1, p2 = parentrevs(r) + if p1 not in seen: + schedule(visit, -p1) + see(p1) + if p2 not in seen: + schedule(visit, -p2) + see(p2) while visit: current = -nextitem(visit) if current < stoprev: break yield current - for parent in parentrevs(current): - if parent not in seen: - schedule(visit, -parent) - see(parent) + p1, p2 = parentrevs(current) + if p1 not in seen: + schedule(visit, -p1) + see(p1) + if p2 not in seen: + schedule(visit, -p2) + see(p2) class lazyancestors(object): def __init__(self, pfunc, revs, stoprev=0, inclusive=False): diff --git a/tests/test-ancestor.py b/tests/test-ancestor.py --- a/tests/test-ancestor.py +++ b/tests/test-ancestor.py @@ -178,9 +178,9 @@ def test_missingancestors(seed, rng): # | # o 0 -graph = {0: [-1], 1: [0], 2: [1], 3: [1], 4: [2], 5: [4], 6: [4], - 7: [4], 8: [-1], 9: [6, 7], 10: [5], 11: [3, 7], 12: [9], - 13: [8]} +graph = {0: [-1, -1], 1: [0, -1], 2: [1, -1], 3: [1, -1], 4: [2, -1], + 5: [4, -1], 6: [4, -1], 7: [4, -1], 8: [-1, -1], 9: [6, 7], + 10: [5, -1], 11: [3, 7], 12: [9, -1], 13: [8, -1]} def genlazyancestors(revs, stoprev=0, inclusive=False): print(("%% lazy ancestor set for %s, stoprev = %s, inclusive = %s" %