hbisect: use a defaultdict to avoid large allocations for a large changelogs
authorDavid Soria Parra <davidsp@fb.com>
Thu, 23 Nov 2017 14:13:14 -0800
changeset 35130 8287df8b7be5
parent 35129 ec25c8275cfa
child 35131 f38c91c74294
hbisect: use a defaultdict to avoid large allocations for a large changelogs We can avoid a SPACE(len(changelog)) allocation by using a defaultdict. Test Plan: python run-tests.py test-bisect* Differential Revision: https://phab.mercurial-scm.org/D1499
mercurial/hbisect.py
--- a/mercurial/hbisect.py	Thu Nov 23 14:12:55 2017 -0800
+++ b/mercurial/hbisect.py	Thu Nov 23 14:13:14 2017 -0800
@@ -38,7 +38,7 @@
 
     def buildancestors(bad, good):
         badrev = min([changelog.rev(n) for n in bad])
-        ancestors = [None] * (len(changelog) + 1)
+        ancestors = collections.defaultdict(lambda: None)
         for rev in repo.revs("descendants(%ln) - ancestors(%ln)", good, good):
             ancestors[rev] = []
         if ancestors[badrev] is None: