Source File
map_swiss.go
Belonging Package
runtime
// Copyright 2014 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.//go:build goexperiment.swissmappackage runtimeimport ()const (// TODO: remove? These are used by tests but not the actual maploadFactorNum = 7loadFactorDen = 8)type maptype = abi.SwissMapType//go:linkname maps_errNilAssign internal/runtime/maps.errNilAssignvar maps_errNilAssign error = plainError("assignment to entry in nil map")//go:linkname maps_mapKeyError internal/runtime/maps.mapKeyErrorfunc ( *abi.SwissMapType, unsafe.Pointer) error {return mapKeyError(, )}func ( *abi.SwissMapType, int64, *maps.Map) *maps.Map {if int64(int()) != {= 0}return makemap(, int(), )}// makemap_small implements Go map creation for make(map[k]v) and// make(map[k]v, hint) when hint is known to be at most abi.SwissMapGroupSlots// at compile time and the map needs to be allocated on the heap.//// makemap_small should be an internal detail,// but widely used packages access it using linkname.// Notable members of the hall of shame include:// - github.com/bytedance/sonic//// Do not remove or change the type signature.// See go.dev/issue/67401.////go:linkname makemap_smallfunc () *maps.Map {return maps.NewEmptyMap()}// makemap implements Go map creation for make(map[k]v, hint).// If the compiler has determined that the map or the first group// can be created on the stack, m and optionally m.dirPtr may be non-nil.// If m != nil, the map can be created directly in m.// If m.dirPtr != nil, it points to a group usable for a small map.//// makemap should be an internal detail,// but widely used packages access it using linkname.// Notable members of the hall of shame include:// - github.com/ugorji/go/codec//// Do not remove or change the type signature.// See go.dev/issue/67401.////go:linkname makemapfunc ( *abi.SwissMapType, int, *maps.Map) *maps.Map {if < 0 {= 0}return maps.NewMap(, uintptr(), , maxAlloc)}// mapaccess1 returns a pointer to h[key]. Never returns nil, instead// it will return a reference to the zero object for the elem type if// the key is not in the map.// NOTE: The returned pointer may keep the whole map live, so don't// hold onto it for very long.//// mapaccess1 is pushed from internal/runtime/maps. We could just call it, but// we want to avoid one layer of call.////go:linkname mapaccess1func ( *abi.SwissMapType, *maps.Map, unsafe.Pointer) unsafe.Pointer// mapaccess2 should be an internal detail,// but widely used packages access it using linkname.// Notable members of the hall of shame include:// - github.com/ugorji/go/codec//// Do not remove or change the type signature.// See go.dev/issue/67401.////go:linkname mapaccess2func ( *abi.SwissMapType, *maps.Map, unsafe.Pointer) (unsafe.Pointer, bool)func ( *abi.SwissMapType, *maps.Map, , unsafe.Pointer) unsafe.Pointer {:= mapaccess1(, , )if == unsafe.Pointer(&zeroVal[0]) {return}return}func ( *abi.SwissMapType, *maps.Map, , unsafe.Pointer) (unsafe.Pointer, bool) {:= mapaccess1(, , )if == unsafe.Pointer(&zeroVal[0]) {return , false}return , true}// mapassign is pushed from internal/runtime/maps. We could just call it, but// we want to avoid one layer of call.//// mapassign should be an internal detail,// but widely used packages access it using linkname.// Notable members of the hall of shame include:// - github.com/bytedance/sonic// - github.com/RomiChan/protobuf// - github.com/segmentio/encoding// - github.com/ugorji/go/codec//// Do not remove or change the type signature.// See go.dev/issue/67401.////go:linkname mapassignfunc ( *abi.SwissMapType, *maps.Map, unsafe.Pointer) unsafe.Pointer// mapdelete should be an internal detail,// but widely used packages access it using linkname.// Notable members of the hall of shame include:// - github.com/ugorji/go/codec//// Do not remove or change the type signature.// See go.dev/issue/67401.////go:linkname mapdeletefunc ( *abi.SwissMapType, *maps.Map, unsafe.Pointer) {if raceenabled && != nil {:= sys.GetCallerPC():= abi.FuncPCABIInternal()racewritepc(unsafe.Pointer(), , )raceReadObjectPC(.Key, , , )}if msanenabled && != nil {msanread(, .Key.Size_)}if asanenabled && != nil {asanread(, .Key.Size_)}.Delete(, )}// mapIterStart initializes the Iter struct used for ranging over maps and// performs the first step of iteration. The Iter struct pointed to by 'it' is// allocated on the stack by the compilers order pass or on the heap by// reflect. Both need to have zeroed it since the struct contains pointers.func ( *abi.SwissMapType, *maps.Map, *maps.Iter) {if raceenabled && != nil {:= sys.GetCallerPC()racereadpc(unsafe.Pointer(), , abi.FuncPCABIInternal())}.Init(, ).Next()}// mapIterNext performs the next step of iteration. Afterwards, the next// key/elem are in it.Key()/it.Elem().func ( *maps.Iter) {if raceenabled {:= sys.GetCallerPC()racereadpc(unsafe.Pointer(.Map()), , abi.FuncPCABIInternal())}.Next()}// mapclear deletes all keys from a map.func ( *abi.SwissMapType, *maps.Map) {if raceenabled && != nil {:= sys.GetCallerPC():= abi.FuncPCABIInternal()racewritepc(unsafe.Pointer(), , )}.Clear()}// Reflect stubs. Called from ../reflect/asm_*.s// reflect_makemap is for package reflect,// but widely used packages access it using linkname.// Notable members of the hall of shame include:// - gitee.com/quant1x/gox// - github.com/modern-go/reflect2// - github.com/goccy/go-json// - github.com/RomiChan/protobuf// - github.com/segmentio/encoding// - github.com/v2pro/plz//// Do not remove or change the type signature.// See go.dev/issue/67401.////go:linkname reflect_makemap reflect.makemapfunc ( *abi.SwissMapType, int) *maps.Map {// Check invariants and reflects math.if .Key.Equal == nil {throw("runtime.reflect_makemap: unsupported map key type")}// TODO: other checksreturn makemap(, , nil)}// reflect_mapaccess is for package reflect,// but widely used packages access it using linkname.// Notable members of the hall of shame include:// - gitee.com/quant1x/gox// - github.com/modern-go/reflect2// - github.com/v2pro/plz//// Do not remove or change the type signature.// See go.dev/issue/67401.////go:linkname reflect_mapaccess reflect.mapaccessfunc ( *abi.SwissMapType, *maps.Map, unsafe.Pointer) unsafe.Pointer {, := mapaccess2(, , )if ! {// reflect wants nil for a missing element= nil}return}//go:linkname reflect_mapaccess_faststr reflect.mapaccess_faststrfunc ( *abi.SwissMapType, *maps.Map, string) unsafe.Pointer {, := mapaccess2_faststr(, , )if ! {// reflect wants nil for a missing element= nil}return}// reflect_mapassign is for package reflect,// but widely used packages access it using linkname.// Notable members of the hall of shame include:// - gitee.com/quant1x/gox// - github.com/v2pro/plz//// Do not remove or change the type signature.////go:linkname reflect_mapassign reflect.mapassign0func ( *abi.SwissMapType, *maps.Map, unsafe.Pointer, unsafe.Pointer) {:= mapassign(, , )typedmemmove(.Elem, , )}//go:linkname reflect_mapassign_faststr reflect.mapassign_faststr0func ( *abi.SwissMapType, *maps.Map, string, unsafe.Pointer) {:= mapassign_faststr(, , )typedmemmove(.Elem, , )}//go:linkname reflect_mapdelete reflect.mapdeletefunc ( *abi.SwissMapType, *maps.Map, unsafe.Pointer) {mapdelete(, , )}//go:linkname reflect_mapdelete_faststr reflect.mapdelete_faststrfunc ( *abi.SwissMapType, *maps.Map, string) {mapdelete_faststr(, , )}// reflect_maplen is for package reflect,// but widely used packages access it using linkname.// Notable members of the hall of shame include:// - github.com/goccy/go-json// - github.com/wI2L/jettison//// Do not remove or change the type signature.// See go.dev/issue/67401.////go:linkname reflect_maplen reflect.maplenfunc ( *maps.Map) int {if == nil {return 0}if raceenabled {:= sys.GetCallerPC()racereadpc(unsafe.Pointer(), , abi.FuncPCABIInternal())}return int(.Used())}//go:linkname reflect_mapclear reflect.mapclearfunc ( *abi.SwissMapType, *maps.Map) {mapclear(, )}//go:linkname reflectlite_maplen internal/reflectlite.maplenfunc ( *maps.Map) int {if == nil {return 0}if raceenabled {:= sys.GetCallerPC()racereadpc(unsafe.Pointer(), , abi.FuncPCABIInternal(reflect_maplen))}return int(.Used())}// mapinitnoop is a no-op function known the Go linker; if a given global// map (of the right size) is determined to be dead, the linker will// rewrite the relocation (from the package init func) from the outlined// map init function to this symbol. Defined in assembly so as to avoid// complications with instrumentation (coverage, etc).func ()// mapclone for implementing maps.Clone////go:linkname mapclone maps.clonefunc ( any) any {:= efaceOf(&).data = unsafe.Pointer(mapclone2((*abi.SwissMapType)(unsafe.Pointer(._type)), (*maps.Map)(.data)))return}func ( *abi.SwissMapType, *maps.Map) *maps.Map {:= makemap(, int(.Used()), nil)var maps.Iter.Init(, )for .Next(); .Key() != nil; .Next() {.Put(, .Key(), .Elem())}return}// keys for implementing maps.keys////go:linkname keys maps.keysfunc ( any, unsafe.Pointer) {// Currently unused in the maps package.panic("unimplemented")}// values for implementing maps.values////go:linkname values maps.valuesfunc ( any, unsafe.Pointer) {// Currently unused in the maps package.panic("unimplemented")}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)