Source File
rtype.go
Belonging Package
github.com/goccy/go-json/internal/runtime
package runtimeimport ()type emptyInterface struct {typ unsafe.Pointerptr unsafe.Pointer}// TypePtr returns the pointer to the type descriptor of the type.// It is the type word of an interface value which holds a value of the type,// and it is what the functions of the runtime package take as a type.func ( reflect.Type) unsafe.Pointer {return (*emptyInterface)(unsafe.Pointer(&)).ptr}// TypeOfPtr converts the pointer to the type descriptor to reflect.Type.// reflect.TypeOf reads only the type word of the interface value, so the data word is left nil.func ( unsafe.Pointer) reflect.Type {return reflect.TypeOf(*(*any)(unsafe.Pointer(&emptyInterface{typ: })))}// IfaceIndir reports whether a value of the type is stored indirectly in an interface value:// the data word of the interface points to a copy of the value, instead of being the value itself.//// Which types are stored directly is decided by the compiler and the rule depends on the Go version// ( e.g. a struct of a zero-sized field and a pointer is direct since Go 1.26 ), so the rule is not// reimplemented here. Instead, a value whose first word is a known pointer is converted to an interface// value, and the data word tells how it was stored.func ( reflect.Type) bool {if .Size() != unsafe.Sizeof(unsafe.Pointer(nil)) {// only a pointer-sized value fits in the data word.return true}:= unsafe.Pointer(new(uintptr)):= reflect.New()*(*unsafe.Pointer)(.UnsafePointer()) =:= .Elem().Interface()return (*emptyInterface)(unsafe.Pointer(&)).ptr !=}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |