1
0
mirror of https://github.com/golang/go synced 2024-11-11 16:41:37 -07:00

encoding/gob: make use of maps.Clone

Change-Id: I4e9a7fd1dd3275c3da5500c9c4bf687b77f53107
This commit is contained in:
Jes Cok 2024-09-13 00:26:29 +08:00
parent 8a4b439ee6
commit 8c295bf55f

View File

@ -8,6 +8,7 @@ import (
"encoding"
"errors"
"fmt"
"maps"
"os"
"reflect"
"sync"
@ -779,10 +780,7 @@ func buildTypeInfo(ut *userTypeInfo, rt reflect.Type) (*typeInfo, error) {
// Create new map with old contents plus new entry.
m, _ := typeInfoMap.Load().(map[reflect.Type]*typeInfo)
newm := make(map[reflect.Type]*typeInfo, len(m))
for k, v := range m {
newm[k] = v
}
newm := maps.Clone(m)
newm[rt] = info
typeInfoMap.Store(newm)
return info, nil