[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 <tamer.ahmed@microsoft.com>
This commit is contained in:
Tamer Ahmed 2020-09-28 22:52:18 -07:00 committed by Tamer Ahmed
parent 110f7b7817
commit 57a584997a

View File

@ -197,12 +197,16 @@ TODO(taoyl): Current version of config db only supports BGP admin states.
def deep_update(dst, src): def deep_update(dst, src):
for key, value in src.items(): """ Deep update of dst dict with contest of src dict"""
if isinstance(value, dict): pending_nodes = [(dst, src)]
node = dst.setdefault(key, {}) while len(pending_nodes) > 0:
deep_update(node, value) d, s = pending_nodes.pop(0)
else: for key, value in s.items():
dst[key] = value if isinstance(value, dict):
node = d.setdefault(key, type(value)())
pending_nodes.append((node, value))
else:
d[key] = value
return dst return dst
# sort_data is required as it is being imported by config/config_mgmt module in sonic_utilities # sort_data is required as it is being imported by config/config_mgmt module in sonic_utilities