bisect: use array.array rather than lists for ancestor lists
authorMatt Mackall <mpm@selenic.com>
Thu, 27 Dec 2007 23:55:39 -0600
changeset 5727 1325ebc29e29
parent 5726 19cbe2aea2bc
child 5728 f3374025fe09
bisect: use array.array rather than lists for ancestor lists This nearly doubles performance and cuts memory usage in half on large bisections.
hgext/hbisect.py
--- a/hgext/hbisect.py	Thu Dec 27 23:55:39 2007 -0600
+++ b/hgext/hbisect.py	Thu Dec 27 23:55:39 2007 -0600
@@ -8,7 +8,7 @@
 
 from mercurial.i18n import _
 from mercurial import hg, util, commands, cmdutil
-import os, sys
+import os, sys, array
 
 class bisect(object):
     """dichotomic search in the DAG of changesets"""
@@ -104,13 +104,13 @@
                         a = dict.fromkeys(a2)
                         a.update(dict.fromkeys(a1))
                         a[rev] = None
-                        ancestors[rev] = a.keys()
+                        ancestors[rev] = array.array("l", a.keys())
                     else:
-                        ancestors[rev] = a1 + [rev]
+                        ancestors[rev] = a1 + array.array("l", [rev])
                 elif a2:
-                    ancestors[rev] = a2 + [rev]
+                    ancestors[rev] = a2 + array.array("l", [rev])
                 else:
-                    ancestors[rev] = [rev]
+                    ancestors[rev] = array.array("l", [rev])
 
         if badrev not in ancestors[badrev]:
             raise util.Abort(_("Could not find the first bad revision"))