dagop: just compare with the last value to deduplicate input of revancestors()
authorYuya Nishihara <yuya@tcha.org>
Sun, 18 Jun 2017 08:59:09 +0900
changeset 33000 d3d36bcdf036
parent 32999 08e2793d9f65
child 33001 92d0945a15e0
dagop: just compare with the last value to deduplicate input of revancestors() Since we're using a max heap, the current rev should be a duplicate only if it equals to the previous one. We don't have to maintain the whole seen set. # reverse(ancestors(tip)) using hg repo 0) 0.086420 1) 0.081051
mercurial/dagop.py
--- a/mercurial/dagop.py	Sun Jun 18 17:22:57 2017 +0900
+++ b/mercurial/dagop.py	Sun Jun 18 08:59:09 2017 +0900
@@ -37,15 +37,15 @@
     if inputrev is not None:
         heapq.heappush(pendingheap, -inputrev)
 
-    seen = set()
+    lastrev = None
     while pendingheap:
         currev = -heapq.heappop(pendingheap)
         if currev == inputrev:
             inputrev = next(irevs, None)
             if inputrev is not None:
                 heapq.heappush(pendingheap, -inputrev)
-        if currev not in seen:
-            seen.add(currev)
+        if currev != lastrev:
+            lastrev = currev
             yield currev
             try:
                 for prev in cl.parentrevs(currev)[:cut]: