Mercurial > hg-stable
changeset 39552:b9ee9c2e10dd
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 10 Sep 2018 21:54:40 +0900 |
parents | fd9029d36c41 |
children | bdb177923291 |
files | mercurial/ancestor.py tests/test-ancestor.py |
diffstat | 2 files changed, 17 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/ancestor.py Mon Sep 10 21:46:19 2018 +0900 +++ b/mercurial/ancestor.py Mon Sep 10 21:54:40 2018 +0900 @@ -274,20 +274,26 @@ 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):
--- a/tests/test-ancestor.py Mon Sep 10 21:46:19 2018 +0900 +++ b/tests/test-ancestor.py Mon Sep 10 21:54:40 2018 +0900 @@ -178,9 +178,9 @@ # | # 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" %