bisect: use a dict for children
authorMatt Mackall <mpm@selenic.com>
Mon, 31 Dec 2007 18:20:33 -0600
changeset 5768 78d14403bdc7
parent 5767 dd5f8ed31057
child 5769 49809f4a38d8
bisect: use a dict for children We fill in the children only for ancestors of badrev
hgext/hbisect.py
--- a/hgext/hbisect.py	Mon Dec 31 18:20:33 2007 -0600
+++ b/hgext/hbisect.py	Mon Dec 31 18:20:33 2007 -0600
@@ -31,18 +31,19 @@
         raise util.Abort(_("Inconsistent state, %s:%s is good and bad")
                          % (badrev, hg.short(bad)))
 
-    # build children array
-    children = [[]] * (badrev + 1) # an extra for [-1]
-    for rev in xrange(badrev, -1, -1):
+    # build children dict
+    children = {}
+    visit = [badrev]
+    while visit:
+        rev = visit.pop(0)
         if ancestors[rev] == []:
             for prev in clparents(rev):
-                if prev == -1:
-                    continue
-                l = children[prev]
-                if l:
-                    l.append(rev)
-                else:
-                    children[prev] = [rev]
+                if prev != -1:
+                    if prev in children:
+                        children[prev].append(rev)
+                    else:
+                        children[prev] = [rev]
+                        visit.append(prev)
 
     # accumulate ancestor lists
     for rev in xrange(badrev + 1):
@@ -58,7 +59,7 @@
                     a.update(dict.fromkeys(s))
                 a[rev] = None
                 a = a.keys()
-            for c in children[rev]:
+            for c in children.get(rev, []):
                 if ancestors[c]:
                     ancestors[c].append(a)
                 else: