ancestors: simplify symmetric difference
authorMatt Mackall <mpm@selenic.com>
Sat, 29 Mar 2008 12:39:47 -0500
changeset 6427 6b704ef9ed06
parent 6426 e2c49ef2dd6e
child 6428 cbdefda439b6
ancestors: simplify symmetric difference - n_wanted/wanted -> interesting - scan colors rather than managing ret
mercurial/ancestor.py
--- a/mercurial/ancestor.py	Sat Mar 29 12:39:47 2008 -0500
+++ b/mercurial/ancestor.py	Sat Mar 29 12:39:47 2008 -0500
@@ -107,28 +107,24 @@
 
     visit = [-a, -b]
     heapq.heapify(visit)
-    n_wanted = len(visit)
-    ret = []
+    interesting = len(visit)
 
-    while n_wanted:
+    while interesting:
         r = -heapq.heappop(visit)
-        wanted = colors[r] != ALLCOLORS
-        n_wanted -= wanted
-        if wanted:
-            ret.append(r)
+        if colors[r] != ALLCOLORS:
+            interesting -= 1
 
         for p in pfunc(r):
             if p not in colors:
                 # first time we see p; add it to visit
-                n_wanted += wanted
                 colors[p] = colors[r]
+                if colors[p] != ALLCOLORS:
+                    interesting += 1
                 heapq.heappush(visit, -p)
             elif colors[p] != ALLCOLORS and colors[p] != colors[r]:
                 # at first we thought we wanted p, but now
                 # we know we don't really want it
-                n_wanted -= 1
                 colors[p] |= colors[r]
+                interesting -= 1
 
-        del colors[r]
-
-    return ret
+    return [r for r in colors if colors[r] != ALLCOLORS]