From 57a584997ae2a44174e6ee725885a8a906c46847 Mon Sep 17 00:00:00 2001 From: Tamer Ahmed Date: Mon, 28 Sep 2020 22:52:18 -0700 Subject: [PATCH] [cfggen] Iterative Version Of Deep Update Avoiding recursive update of maps as it consumes stack frames. This PR introduces iterative version of deep_update method. signed-off-by: Tamer Ahmed --- src/sonic-config-engine/sonic-cfggen | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index 892647a757..de99d25230 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -197,12 +197,16 @@ TODO(taoyl): Current version of config db only supports BGP admin states. def deep_update(dst, src): - for key, value in src.items(): - if isinstance(value, dict): - node = dst.setdefault(key, {}) - deep_update(node, value) - else: - dst[key] = value + """ Deep update of dst dict with contest of src dict""" + pending_nodes = [(dst, src)] + while len(pending_nodes) > 0: + d, s = pending_nodes.pop(0) + for key, value in s.items(): + if isinstance(value, dict): + node = d.setdefault(key, type(value)()) + pending_nodes.append((node, value)) + else: + d[key] = value return dst # sort_data is required as it is being imported by config/config_mgmt module in sonic_utilities