]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/gob: change typeInfo.encoder type to atomic.Pointer[T]
authorLudi Rehak <ludi317@gmail.com>
Mon, 8 Aug 2022 21:13:52 +0000 (14:13 -0700)
committerRob Pike <r@golang.org>
Tue, 9 Aug 2022 21:26:45 +0000 (21:26 +0000)
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>

src/encoding/gob/encode.go
src/encoding/gob/type.go

index 548d614f524740c1d490d374185a2c62838e9cee..38430342b61c9def17427f0894473d10811bd5a6 100644 (file)
@@ -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)
                }
index 6e2c7242324fa17eb111f3b9057027589cf2a06b..9eec08615e11c9e3d678dd78bb0addec845e71bb 100644 (file)
@@ -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
 }