From 490a943475f120a5d717ed53227831589b46b1bc Mon Sep 17 00:00:00 2001 From: nialdaly Date: Thu, 5 Dec 2024 17:29:10 +0000 Subject: [PATCH] [From review] Modify dest map in-place in the mergeMaps method --- pkg/provider/helm/values.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/pkg/provider/helm/values.go b/pkg/provider/helm/values.go index b3bcee6..9d308f6 100644 --- a/pkg/provider/helm/values.go +++ b/pkg/provider/helm/values.go @@ -426,26 +426,20 @@ func getOrCreateNestedMap(m map[string]any, key string) (map[string]any, error) // mergeMaps merges the source map into the destination map, returning a new merged map. func mergeMaps(dest, src map[string]any) map[string]any { - merged := make(map[string]any) - - for key, value := range dest { - merged[key] = value - } - for key, value := range src { if srcMap, isSrcMap := value.(map[string]any); isSrcMap { - if destMap, isDestMap := merged[key].(map[string]any); isDestMap { - merged[key] = mergeMaps(destMap, srcMap) + if destMap, isDestMap := dest[key].(map[string]any); isDestMap { + dest[key] = mergeMaps(destMap, srcMap) } else { - merged[key] = srcMap + dest[key] = srcMap } } else { // Always overwrite existing keys. - merged[key] = value + dest[key] = value } } - return merged + return dest } // shallowMerge flattens a slice of maps into a single map.