1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Improve efficiency of merge_hash

This is related to #14559, but only the part for Ansible v2.0

This commit makes merging empty dicts, or equal dicts more efficient.

I noticed that while debugging merge_hash a lot of merges related to empty dictionaries and sometimes also identical dictionaries.
This commit is contained in:
Dag Wieers 2016-02-18 15:59:57 +01:00
parent 54942ee8ff
commit 5a57139d91

View file

@ -74,6 +74,12 @@ def merge_hash(a, b):
"""
_validate_mutable_mappings(a, b)
# if a is empty or equal to b, return b
if a == {} or a == b:
return b.copy()
# if b is empty the below unfolds quickly
result = a.copy()
# next, iterate over b keys and values