Documentation
¶
Index ¶
- Constants
- Variables
- func AppendTextMethod(typ reflect.Type) (reflect.Method, bool)
- func IfaceIndir(typ reflect.Type) bool
- func IsIgnoredStructField(field reflect.StructField) bool
- func IsStdMarshalerType(typ reflect.Type) bool
- func MarshalJSONMethod(typ reflect.Type) (reflect.Method, bool)
- func MarshalTextMethod(typ reflect.Type) (reflect.Method, bool)
- func PromotedStdMethod(typ reflect.Type, method MethodLookup) (reflect.Type, uintptr, bool, bool)
- func TypeOfPtr(typ unsafe.Pointer) reflect.Type
- func TypePtr(t reflect.Type) unsafe.Pointer
- func UnmarshalJSONMethod(typ reflect.Type) (reflect.Method, bool)
- type MethodLookup
- type SliceHeader
- type StructTag
- type StructTags
- type TypeCache
Constants ¶
const TypeHashMultiplier = 0x9E3779B97F4A7C15
TypeHashMultiplier is the multiplier of the Fibonacci hashing of the address of a type: the top bits of the product spread the addresses, which are aligned and close to each other, over a table.
Variables ¶
var HasAVX2 = detectAVX2()
HasAVX2 is whether the CPU and the OS support AVX2.
Functions ¶
func AppendTextMethod ¶ added in v0.11.2
AppendTextMethod looks AppendText up.
func IfaceIndir ¶
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 IsIgnoredStructField ¶
func IsIgnoredStructField(field reflect.StructField) bool
func IsStdMarshalerType ¶ added in v0.11.2
IsStdMarshalerType is whether the type, or the type it points to, is a named type of a package of the standard library whose marshalers are trusted: what MarshalJSON returns is valid and compact, AppendText appends what MarshalText returns, and UnmarshalJSON and UnmarshalText keep nothing of the bytes they are given.
func MarshalJSONMethod ¶ added in v0.11.2
MarshalJSONMethod looks MarshalJSON up.
func MarshalTextMethod ¶ added in v0.11.2
MarshalTextMethod looks MarshalText up.
func PromotedStdMethod ¶ added in v0.11.2
PromotedStdMethod reports whether the method of the type which the lookup finds, or the one of the type it points to, is the method of a type of the standard library whose marshalers are trusted ( see IsStdMarshalerType ), which the type has by embedding it and doesn't declare itself: a call of the method then runs the method of that type, on the embedded value. It returns that type and, if the embedded value is in the value of the type ( embedded by value at every depth ), its offset in it, and whether it is so ( inline ), and whether the method is such a method. A type which declares the method, or which has it from more than one embedded type at one depth, is not such a type.
func TypeOfPtr ¶ added in v0.11.0
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.
Types ¶
type MethodLookup ¶ added in v0.11.2
MethodLookup looks the method of one name up in a type, by reflect.Type.MethodByName with the name as a constant.
The compiler tells the linker which names the calls of Method and MethodByName of reflect look up when it sees them as constants, and the linker keeps the methods of those names only. A call with any other argument makes the linker keep every exported method of every type of the program ( cmd/compile/internal/walk.usemethod ), so the methods are looked up by these functions, each with its name in its code, and never by a name in a variable.
type StructTag ¶
type StructTag struct {
Key string
IsTaggedKey bool
IsOmitEmpty bool
// IsOmitZero is whether the field has the omitzero option, which encoding/json has from Go 1.24: it is
// false with an older Go, whose encoding/json ignores the option.
IsOmitZero bool
IsString bool
Field reflect.StructField
}
func StructTagFromField ¶
func StructTagFromField(field reflect.StructField) *StructTag
type StructTags ¶
type StructTags []*StructTag
func (StructTags) ExistsKey ¶
func (t StructTags) ExistsKey(key string) bool
type TypeCache ¶ added in v0.11.0
type TypeCache[T any] struct { // contains filtered or unexported fields }
TypeCache is a table of the values for the types, which is looked up by the address of a type without a lock.
It is a hash table with open addressing. It used to be an array which had a slot for every address a type of the program can be at, which was found from the type links of the runtime: that needed a linkname, a scan of every type at the start, memory in proportion to the size of the program, and a fallback for the types which are not in the type links. A lookup of this table costs about the same, and it has none of them.
The zero value is ready to use.