package reflect
import (
)
type mapType = abi.SwissMapType
func ( *rtype) () Type {
if .Kind() != Map {
panic("reflect: Key of non-map type " + .String())
}
:= (*mapType)(unsafe.Pointer())
return toType(.Key)
}
func (, Type) Type {
:= .common()
:= .common()
if .Equal == nil {
panic("reflect.MapOf: invalid key type " + stringFor())
}
:= cacheKey{Map, , , 0}
if , := lookupCache.Load(); {
return .(Type)
}
:= "map[" + stringFor() + "]" + stringFor()
for , := range typesByString() {
:= (*mapType)(unsafe.Pointer())
if .Key == && .Elem == {
, := lookupCache.LoadOrStore(, toRType())
return .(Type)
}
}
, := groupAndSlotOf(, )
var any = (map[unsafe.Pointer]unsafe.Pointer)(nil)
:= **(**mapType)(unsafe.Pointer(&))
.Str = resolveReflectName(newName(, "", false, false))
.TFlag = 0
.Hash = fnv1(.Hash, 'm', byte(.Hash>>24), byte(.Hash>>16), byte(.Hash>>8), byte(.Hash))
.Key =
.Elem =
.Group = .common()
.Hasher = func( unsafe.Pointer, uintptr) uintptr {
return typehash(, , )
}
.GroupSize = .Group.Size()
.SlotSize = .Size()
.ElemOff = .Field(1).Offset
.Flags = 0
if needKeyUpdate() {
.Flags |= abi.SwissMapNeedKeyUpdate
}
if hashMightPanic() {
.Flags |= abi.SwissMapHashMightPanic
}
if .Size_ > abi.SwissMapMaxKeyBytes {
.Flags |= abi.SwissMapIndirectKey
}
if .Size_ > abi.SwissMapMaxKeyBytes {
.Flags |= abi.SwissMapIndirectElem
}
.PtrToThis = 0
, := lookupCache.LoadOrStore(, toRType(&.Type))
return .(Type)
}
func (, Type) (Type, Type) {
if .Size() > abi.SwissMapMaxKeyBytes {
= PointerTo()
}
if .Size() > abi.SwissMapMaxElemBytes {
= PointerTo()
}
:= []StructField{
{
Name: "Key",
Type: ,
},
{
Name: "Elem",
Type: ,
},
}
:= StructOf()
= []StructField{
{
Name: "Ctrl",
Type: TypeFor[uint64](),
},
{
Name: "Slots",
Type: ArrayOf(abi.SwissMapGroupSlots, ),
},
}
:= StructOf()
return ,
}
var stringType = rtypeOf("")
func ( Value) ( Value) Value {
.mustBe(Map)
:= (*mapType)(unsafe.Pointer(.typ()))
var unsafe.Pointer
if (.Key == stringType || .kind() == String) && .Key == .typ() && .Elem.Size() <= abi.SwissMapMaxElemBytes {
:= *(*string)(.ptr)
= mapaccess_faststr(.typ(), .pointer(), )
} else {
= .assignTo("reflect.Value.MapIndex", .Key, nil)
var unsafe.Pointer
if .flag&flagIndir != 0 {
= .ptr
} else {
= unsafe.Pointer(&.ptr)
}
= mapaccess(.typ(), .pointer(), )
}
if == nil {
return Value{}
}
:= .Elem
:= (.flag | .flag).ro()
|= flag(.Kind())
return copyVal(, , )
}
func ( *abi.SwissMapType, *maps.Map, *maps.Iter) {
if race.Enabled && != nil {
:= sys.GetCallerPC()
race.ReadPC(unsafe.Pointer(), , abi.FuncPCABIInternal())
}
.Init(, )
.Next()
}
func ( *maps.Iter) {
if race.Enabled {
:= sys.GetCallerPC()
race.ReadPC(unsafe.Pointer(.Map()), , abi.FuncPCABIInternal())
}
.Next()
}
func ( Value) () []Value {
.mustBe(Map)
:= (*mapType)(unsafe.Pointer(.typ()))
:= .Key
:= .flag.ro() | flag(.Kind())
:= abi.NoEscape(.pointer())
:= (*maps.Map)()
:= int(0)
if != nil {
= maplen()
}
var maps.Iter
mapIterStart(, , &)
:= make([]Value, )
var int
for = 0; < len(); ++ {
:= .Key()
if == nil {
break
}
[] = copyVal(, , )
mapIterNext(&)
}
return [:]
}
type MapIter struct {
m Value
hiter maps.Iter
}
type hiter = maps.Iter
func ( *MapIter) () Value {
if !.hiter.Initialized() {
panic("MapIter.Key called before Next")
}
:= .hiter.Key()
if == nil {
panic("MapIter.Key called on exhausted iterator")
}
:= (*mapType)(unsafe.Pointer(.m.typ()))
:= .Key
return copyVal(, .m.flag.ro()|flag(.Kind()), )
}
func ( Value) ( *MapIter) {
if !.hiter.Initialized() {
panic("reflect: Value.SetIterKey called before Next")
}
:= .hiter.Key()
if == nil {
panic("reflect: Value.SetIterKey called on exhausted iterator")
}
.mustBeAssignable()
var unsafe.Pointer
if .kind() == Interface {
= .ptr
}
:= (*mapType)(unsafe.Pointer(.m.typ()))
:= .Key
.m.mustBeExported()
:= Value{, , .m.flag | flag(.Kind()) | flagIndir}
= .assignTo("reflect.MapIter.SetKey", .typ(), )
typedmemmove(.typ(), .ptr, .ptr)
}
func ( *MapIter) () Value {
if !.hiter.Initialized() {
panic("MapIter.Value called before Next")
}
:= .hiter.Elem()
if == nil {
panic("MapIter.Value called on exhausted iterator")
}
:= (*mapType)(unsafe.Pointer(.m.typ()))
:= .Elem
return copyVal(, .m.flag.ro()|flag(.Kind()), )
}
func ( Value) ( *MapIter) {
if !.hiter.Initialized() {
panic("reflect: Value.SetIterValue called before Next")
}
:= .hiter.Elem()
if == nil {
panic("reflect: Value.SetIterValue called on exhausted iterator")
}
.mustBeAssignable()
var unsafe.Pointer
if .kind() == Interface {
= .ptr
}
:= (*mapType)(unsafe.Pointer(.m.typ()))
:= .Elem
.m.mustBeExported()
:= Value{, , .m.flag | flag(.Kind()) | flagIndir}
= .assignTo("reflect.MapIter.SetValue", .typ(), )
typedmemmove(.typ(), .ptr, .ptr)
}
func ( *MapIter) () bool {
if !.m.IsValid() {
panic("MapIter.Next called on an iterator that does not have an associated map Value")
}
if !.hiter.Initialized() {
:= (*mapType)(unsafe.Pointer(.m.typ()))
:= (*maps.Map)(.m.pointer())
mapIterStart(, , &.hiter)
} else {
if .hiter.Key() == nil {
panic("MapIter.Next called on exhausted iterator")
}
mapIterNext(&.hiter)
}
return .hiter.Key() != nil
}
func ( *MapIter) ( Value) {
if .IsValid() {
.mustBe(Map)
}
.m =
.hiter = maps.Iter{}
}
func ( Value) () *MapIter {
if .kind() != Map {
.panicNotMap()
}
return &MapIter{m: }
}
func ( Value) (, Value) {
.mustBe(Map)
.mustBeExported()
.mustBeExported()
:= (*mapType)(unsafe.Pointer(.typ()))
if (.Key == stringType || .kind() == String) && .Key == .typ() && .Elem.Size() <= abi.SwissMapMaxElemBytes {
:= *(*string)(.ptr)
if .typ() == nil {
mapdelete_faststr(.typ(), .pointer(), )
return
}
.mustBeExported()
= .assignTo("reflect.Value.SetMapIndex", .Elem, nil)
var unsafe.Pointer
if .flag&flagIndir != 0 {
= .ptr
} else {
= unsafe.Pointer(&.ptr)
}
mapassign_faststr(.typ(), .pointer(), , )
return
}
= .assignTo("reflect.Value.SetMapIndex", .Key, nil)
var unsafe.Pointer
if .flag&flagIndir != 0 {
= .ptr
} else {
= unsafe.Pointer(&.ptr)
}
if .typ() == nil {
mapdelete(.typ(), .pointer(), )
return
}
.mustBeExported()
= .assignTo("reflect.Value.SetMapIndex", .Elem, nil)
var unsafe.Pointer
if .flag&flagIndir != 0 {
= .ptr
} else {
= unsafe.Pointer(&.ptr)
}
mapassign(.typ(), .pointer(), , )
}
func ( flag) () {
.mustBe(Map)
}