Patchwork [6,of,9,"] discovery: simplify the building of the children mapping

login
register
mail settings
Submitter Pierre-Yves David
Date March 5, 2019, 5:39 p.m.
Message ID <1d2a2e4a255fcc8e5713.1551807557@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/39082/
State Accepted
Headers show

Comments

Pierre-Yves David - March 5, 2019, 5:39 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1551796794 -3600
#      Tue Mar 05 15:39:54 2019 +0100
# Node ID 1d2a2e4a255fcc8e5713232f5f80858a7b3793e1
# Parent  3f4f517d5ed962a0c2aef538ac81bfab28341355
# EXP-Topic discovery-speedup
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 1d2a2e4a255f
discovery: simplify the building of the children mapping

Since we only care about the revisions inside the set we are sampling, we can
use simpler code (and probably sightly faster).

Patch

diff --git a/mercurial/setdiscovery.py b/mercurial/setdiscovery.py
--- a/mercurial/setdiscovery.py
+++ b/mercurial/setdiscovery.py
@@ -219,13 +219,13 @@  class partialdiscovery(object):
         for rev in sorted(revs):
             # Always ensure revision has an entry so we don't need to worry
             # about missing keys.
-            children.setdefault(rev, [])
-
+            children[rev] = []
             for prev in parentrevs(rev):
                 if prev == nullrev:
                     continue
-
-                children.setdefault(prev, []).append(rev)
+                c = children.get(prev)
+                if c is not None:
+                    c.append(rev)
 
         _updatesample(revs, revsroots, sample, children.__getitem__)
         assert sample