MCPcopy
hub / github.com/duke-git/lancet / clonePtr

Method clonePtr

convertor/convertor_internal.go:155–186  ·  view source on GitHub ↗
(v reflect.Value)

Source from the content-addressed store, hash-verified

153}
154
155func (c *cloner) clonePtr(v reflect.Value) reflect.Value {
156 if v.IsNil() {
157 return reflect.Zero(v.Type())
158 }
159
160 var newVal reflect.Value
161
162 if v.Elem().CanAddr() {
163 ptrs, exists := c.ptrs[v.Type()]
164 if exists {
165 if newVal, exists := ptrs[v.Elem().UnsafeAddr()]; exists {
166 return newVal
167 }
168 }
169 }
170
171 newVal = c.clone(v.Elem())
172
173 if v.Elem().CanAddr() {
174 ptrs, exists := c.ptrs[v.Type()]
175 if exists {
176 if newVal, exists := ptrs[v.Elem().UnsafeAddr()]; exists {
177 return newVal
178 }
179 }
180 }
181
182 clonedPtr := reflect.New(newVal.Type())
183 clonedPtr.Elem().Set(newVal)
184
185 return clonedPtr
186}
187
188func (c *cloner) cloneStruct(v reflect.Value) reflect.Value {
189 clonedStructPtr := reflect.New(v.Type())

Callers 1

cloneMethod · 0.95

Calls 4

cloneMethod · 0.95
NewMethod · 0.80
SetMethod · 0.65
IsNilMethod · 0.45

Tested by

no test coverage detected