go.temporal.io/server/common/dynamicconfig/deepcopy.go

78 LOC · 58 covered · 20 uncovered · 14 ranges · 22919 concepts · 7 introducers · 11231 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 package dynamicconfig
2
3 import (
4 "fmt"
5 "reflect"
6 "time"
7 )
8
9 // deepCopyForMapstructure does a simple deep copy of T. Fancy cases (anything other than plain old data)
10 // is not handled and will panic.
11 > func deepCopyForMapstructure[T any](t T) T { setting_gen.go ×51
12 > // nolint:revive // this will be triggered from a static initializer before it can be triggered from production code
13 > return deepCopyValue(reflect.ValueOf(t)).Interface().(T)
14 > }
15
16 > func deepCopyValue(v reflect.Value) reflect.Value { setting_gen.go ×51
17 > switch v.Kind() {
18 case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
19 reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
20 > reflect.Uintptr, reflect.Float32, reflect.Float64, reflect.String: setting_gen.go ×51
21 > nv := reflect.New(v.Type()).Elem()
22 > nv.Set(v)
23 > return nv
24 > case reflect.Array: deepcopy.go ×1
25 > nv := reflect.New(v.Type()).Elem()
26 > for i := range v.Len() {
27 > nv.Index(i).Set(deepCopyValue(v.Index(i)))
28 > }
29 > return nv
30 > case reflect.Map: deepcopy.go ×2
31 > if v.IsNil() {
32 return v
33 }
34 > nv := reflect.MakeMapWithSize(v.Type(), v.Len()) deepcopy.go ×2
35 > for i := v.MapRange(); i.Next(); {
36 > nv.SetMapIndex(i.Key(), deepCopyValue(i.Value()))
37 > }
38 > return nv
39 > case reflect.Pointer: deepcopy.go ×2
40 > if v.IsNil() {
41 > return v deepcopy.go ×1
42 > }
43 > return deepCopyValue(v.Elem()).Addr() deepcopy.go ×2
44 > case reflect.Slice: setting_gen.go ×51
45 > if v.IsNil() {
46 > return v
47 > }
48 > nv := reflect.MakeSlice(v.Type(), v.Len(), v.Len()) deepcopy.go ×1
49 > for i := range v.Len() {
50 > nv.Index(i).Set(deepCopyValue(v.Index(i)))
51 > }
52 > return nv
53 > case reflect.Struct: setting_gen.go ×51
54 > // Special case for time.Time: it has unexported fields so we can't copy it field by
55 > // field, but we can copy zero values (which is all we need for default values).
56 > if v.Type() == reflect.TypeFor[time.Time]() {
57 > if v.Interface().(time.Time).IsZero() {
58 > return reflect.ValueOf(time.Time{})
59 > }
60 // nolint:forbidigo // this will be triggered from a static initializer before it can be triggered from production code
61 panic(fmt.Sprintf("Can't deep copy non-zero time.Time: %v", v.Interface()))
62 }
63 > nv := reflect.New(v.Type()).Elem() setting_gen.go ×51
64 > for i := range v.Type().NumField() {
65 > nv.Field(i).Set(deepCopyValue(v.Field(i)))
66 > }
67 > return nv
68 > case reflect.Interface, reflect.Func, reflect.Chan:
69 > // only nil values of any other reference types allowed!
70 > if v.IsNil() {
71 > return v
72 > }
73 > fallthrough deepcopy.go ×1
74 > default:
75 > // nolint:forbidigo // this will be triggered from a static initializer before it can be triggered from production code
76 > panic(fmt.Sprintf("Can't deep copy value of type %s: %v", v.Type(), v))
77 }
78 }