MCPcopy Create free account
hub / github.com/segmentio/encoding / cachedCodecOf

Function cachedCodecOf

proto/proto.go:168–201  ·  view source on GitHub ↗
(t reflect.Type)

Source from the content-addressed store, hash-verified

166}
167
168func cachedCodecOf(t reflect.Type) *codec {
169 c, oldCache := loadCachedCodec(t)
170 if c != nil {
171 return c
172 }
173
174 var p reflect.Type
175 isPtr := t.Kind() == reflect.Ptr
176 if isPtr {
177 p = t
178 t = t.Elem()
179 } else {
180 p = reflect.PtrTo(t)
181 }
182
183 seen := make(map[reflect.Type]*codec)
184 c1 := codecOf(t, seen)
185 c2 := codecOf(p, seen)
186
187 newCache := make(map[unsafe.Pointer]*codec, len(oldCache)+2)
188 for p, c := range oldCache {
189 newCache[p] = c
190 }
191
192 newCache[pointer(t)] = c1
193 newCache[pointer(p)] = c2
194 storeCachedCodec(newCache)
195
196 if isPtr {
197 return c2
198 } else {
199 return c1
200 }
201}
202
203func codecOf(t reflect.Type, seen map[reflect.Type]*codec) *codec {
204 if c := seen[t]; c != nil {

Callers 4

SizeFunction · 0.85
MarshalFunction · 0.85
MarshalToFunction · 0.85
UnmarshalFunction · 0.85

Calls 6

loadCachedCodecFunction · 0.85
codecOfFunction · 0.85
pointerFunction · 0.85
storeCachedCodecFunction · 0.85
KindMethod · 0.65
ElemMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…