op = func(i *encInstr, state *encoderState, sv reflect.Value) {
state.update(i)
// indirect through info to delay evaluation for recursive structs
- enc := info.encoder.Load().(*encEngine)
+ enc := info.encoder.Load()
state.enc.encodeStruct(state.b, enc, sv)
}
case reflect.Interface:
if err != nil {
error_(err)
}
- enc, ok := info.encoder.Load().(*encEngine)
- if !ok {
+ enc := info.encoder.Load()
+ if enc == nil {
enc = buildEncEngine(info, ut, building)
}
return enc
}
info.encInit.Lock()
defer info.encInit.Unlock()
- enc, ok := info.encoder.Load().(*encEngine)
- if !ok {
+ enc := info.encoder.Load()
+ if enc == nil {
if building == nil {
building = make(map[*typeInfo]bool)
}
type typeInfo struct {
id typeId
- encInit sync.Mutex // protects creation of encoder
- encoder atomic.Value // *encEngine
+ encInit sync.Mutex // protects creation of encoder
+ encoder atomic.Pointer[encEngine]
wire *wireType
}