mirror of
https://github.com/golang/go
synced 2024-11-26 17:36:56 -07:00
encoding/gob: slightly simplify init code
https://go.dev/cl/460543 stopped using the "expect" parameter in bootstrapType, but we forgot to actually remove it. While here, staticcheck correctly points out that we can use the copy builtin to fill builtinIdToTypeSlice, now that it and idToType are an array and slice respectively. Change-Id: I48078415ab9bdd5633cf41f33ab4dc78eb30b48a Reviewed-on: https://go-review.googlesource.com/c/go/+/462301 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Rob Pike <r@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
ffbd194f5c
commit
43f9b826c3
@ -243,22 +243,22 @@ var (
|
|||||||
// Primordial types, needed during initialization.
|
// Primordial types, needed during initialization.
|
||||||
// Always passed as pointers so the interface{} type
|
// Always passed as pointers so the interface{} type
|
||||||
// goes through without losing its interfaceness.
|
// goes through without losing its interfaceness.
|
||||||
tBool = bootstrapType("bool", (*bool)(nil), 1)
|
tBool = bootstrapType("bool", (*bool)(nil))
|
||||||
tInt = bootstrapType("int", (*int)(nil), 2)
|
tInt = bootstrapType("int", (*int)(nil))
|
||||||
tUint = bootstrapType("uint", (*uint)(nil), 3)
|
tUint = bootstrapType("uint", (*uint)(nil))
|
||||||
tFloat = bootstrapType("float", (*float64)(nil), 4)
|
tFloat = bootstrapType("float", (*float64)(nil))
|
||||||
tBytes = bootstrapType("bytes", (*[]byte)(nil), 5)
|
tBytes = bootstrapType("bytes", (*[]byte)(nil))
|
||||||
tString = bootstrapType("string", (*string)(nil), 6)
|
tString = bootstrapType("string", (*string)(nil))
|
||||||
tComplex = bootstrapType("complex", (*complex128)(nil), 7)
|
tComplex = bootstrapType("complex", (*complex128)(nil))
|
||||||
tInterface = bootstrapType("interface", (*any)(nil), 8)
|
tInterface = bootstrapType("interface", (*any)(nil))
|
||||||
// Reserve some Ids for compatible expansion
|
// Reserve some Ids for compatible expansion
|
||||||
tReserved7 = bootstrapType("_reserved1", (*struct{ r7 int })(nil), 9)
|
tReserved7 = bootstrapType("_reserved1", (*struct{ r7 int })(nil))
|
||||||
tReserved6 = bootstrapType("_reserved1", (*struct{ r6 int })(nil), 10)
|
tReserved6 = bootstrapType("_reserved1", (*struct{ r6 int })(nil))
|
||||||
tReserved5 = bootstrapType("_reserved1", (*struct{ r5 int })(nil), 11)
|
tReserved5 = bootstrapType("_reserved1", (*struct{ r5 int })(nil))
|
||||||
tReserved4 = bootstrapType("_reserved1", (*struct{ r4 int })(nil), 12)
|
tReserved4 = bootstrapType("_reserved1", (*struct{ r4 int })(nil))
|
||||||
tReserved3 = bootstrapType("_reserved1", (*struct{ r3 int })(nil), 13)
|
tReserved3 = bootstrapType("_reserved1", (*struct{ r3 int })(nil))
|
||||||
tReserved2 = bootstrapType("_reserved1", (*struct{ r2 int })(nil), 14)
|
tReserved2 = bootstrapType("_reserved1", (*struct{ r2 int })(nil))
|
||||||
tReserved1 = bootstrapType("_reserved1", (*struct{ r1 int })(nil), 15)
|
tReserved1 = bootstrapType("_reserved1", (*struct{ r1 int })(nil))
|
||||||
)
|
)
|
||||||
|
|
||||||
// Predefined because it's needed by the Decoder
|
// Predefined because it's needed by the Decoder
|
||||||
@ -275,9 +275,7 @@ func init() {
|
|||||||
checkId(21, mustGetTypeInfo(reflect.TypeOf((*fieldType)(nil)).Elem()).id)
|
checkId(21, mustGetTypeInfo(reflect.TypeOf((*fieldType)(nil)).Elem()).id)
|
||||||
checkId(23, mustGetTypeInfo(reflect.TypeOf((*mapType)(nil)).Elem()).id)
|
checkId(23, mustGetTypeInfo(reflect.TypeOf((*mapType)(nil)).Elem()).id)
|
||||||
|
|
||||||
for k, v := range idToType {
|
copy(builtinIdToTypeSlice[:], idToType)
|
||||||
builtinIdToTypeSlice[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move the id space upwards to allow for growth in the predefined world
|
// Move the id space upwards to allow for growth in the predefined world
|
||||||
// without breaking existing files.
|
// without breaking existing files.
|
||||||
@ -616,7 +614,7 @@ func checkId(want, got typeId) {
|
|||||||
|
|
||||||
// used for building the basic types; called only from init(). the incoming
|
// used for building the basic types; called only from init(). the incoming
|
||||||
// interface always refers to a pointer.
|
// interface always refers to a pointer.
|
||||||
func bootstrapType(name string, e any, expect typeId) typeId {
|
func bootstrapType(name string, e any) typeId {
|
||||||
rt := reflect.TypeOf(e).Elem()
|
rt := reflect.TypeOf(e).Elem()
|
||||||
_, present := types[rt]
|
_, present := types[rt]
|
||||||
if present {
|
if present {
|
||||||
|
Loading…
Reference in New Issue
Block a user