# HG changeset patch # User Pierre-Yves David # Date 1490333042 -3600 # Node ID 37fa3d83f29422a5de613fc65bba6b4da2dc7a01 # Parent de76219b42b86149a4b8284292b9ccb33581d942 merge-slicing: explain an alternative implementation in a comments It has a better time complexity so a C implementation would likely out perform the current implementation diff -r de76219b42b8 -r 37fa3d83f294 hgext3rd/evolve/stablerange.py --- a/hgext3rd/evolve/stablerange.py Fri Mar 24 06:36:12 2017 +0100 +++ b/hgext3rd/evolve/stablerange.py Fri Mar 24 06:24:02 2017 +0100 @@ -424,9 +424,9 @@ # revision we needs result.append((bottomrevs[-1], rangeid[1])) else: - bheads = set(bottomrevs) parentrevs = cl.parentrevs parents = self._parents + bheads = set(bottomrevs) du = bheads.difference_update reachableroots = repo.changelog.reachableroots for r in bottomrevs: @@ -442,6 +442,31 @@ start = self.depthrev(repo, h) - len(hrevs) entry = (h, start) result.append(entry) + + # Talking about python code being slow, the following code is an + # alternative implementation. + # + # It complexity is better since is does a single traversal on the + # bottomset. However since it is all python it end up being + # slower. + # I'm keeping it here as an inspiration for a future C version + # branches = [] + # for current in reversed(bottomrevs): + # ps = parents(current, parentrevs) + # found = False + # for brevs, bexpect in branches: + # if current in bexpect: + # found = True + # brevs.append(current) + # bexpect.discard(current) + # bexpect.update(ps) + # if not found: + # branches.append(([current], set(ps))) + # for revs, __ in reversed(branches): + # head = revs[0] + # index = self.depthrev(repo, head) - len(revs) + # result.append((head, index)) + # top part is trivial top = (rangeid[0], globalindex) result.append(top)