MCPcopy
hub / github.com/tinode/chat / mergeMaps

Function mergeMaps

server/utils.go:835–877  ·  view source on GitHub ↗

Deep copy maps.

(dst, src map[string]any)

Source from the content-addressed store, hash-verified

833
834// Deep copy maps.
835func mergeMaps(dst, src map[string]any) (map[string]any, bool) {
836 var changed bool
837
838 if len(src) == 0 {
839 return dst, changed
840 }
841
842 if dst == nil {
843 dst = make(map[string]any)
844 }
845
846 for key, val := range src {
847 xval := reflect.ValueOf(val)
848 switch xval.Kind() {
849 case reflect.Map:
850 if xsrc, _ := val.(map[string]any); xsrc != nil {
851 // Deep-copy map[string]any
852 xdst, _ := dst[key].(map[string]any)
853 var lchange bool
854 dst[key], lchange = mergeMaps(xdst, xsrc)
855 changed = changed || lchange
856 } else if val != nil {
857 // The map is shallow-copied if it's not of the type map[string]any
858 dst[key] = val
859 changed = true
860 }
861 case reflect.String:
862 changed = true
863 if xval.String() == nullValue {
864 delete(dst, key)
865 } else if val != nil {
866 dst[key] = val
867 }
868 default:
869 if val != nil {
870 dst[key] = val
871 changed = true
872 }
873 }
874 }
875
876 return dst, changed
877}
878
879// Shallow copy of a map
880func copyMap(src map[string]any) map[string]any {

Callers 3

TestMergeMapsFunction · 0.85
mergeInterfacesFunction · 0.85
replySetAuxMethod · 0.85

Calls 1

StringMethod · 0.45

Tested by 1

TestMergeMapsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…