changeset 5768:78d14403bdc7

bisect: use a dict for children We fill in the children only for ancestors of badrev
author Matt Mackall <mpm@selenic.com>
date Mon, 31 Dec 2007 18:20:33 -0600
parents dd5f8ed31057
children 49809f4a38d8
files hgext/hbisect.py
diffstat 1 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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: