mirror of https://github.com/golang/go.git
encoding/gob: change typeInfo.encoder type to atomic.Pointer[T]
Replace loading and storing an atomic.Value of type pointer with atomic.Pointer. Change-Id: I018ac1e18eee4f203ebca65c2833daf991075371 Reviewed-on: https://go-review.googlesource.com/c/go/+/422174 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Rob Pike <r@golang.org>
This commit is contained in:
parent
cd9cd925bb
commit
d39b54171a
|
|
@ -577,7 +577,7 @@ func encOpFor(rt reflect.Type, inProgress map[reflect.Type]*encOp, building map[
|
|||
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:
|
||||
|
|
@ -661,8 +661,8 @@ func getEncEngine(ut *userTypeInfo, building map[*typeInfo]bool) *encEngine {
|
|||
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
|
||||
|
|
@ -675,8 +675,8 @@ func buildEncEngine(info *typeInfo, ut *userTypeInfo, building map[*typeInfo]boo
|
|||
}
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -672,8 +672,8 @@ func (w *wireType) string() string {
|
|||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue