1
2
3
4
5
6
7
8
9
10 package maps
11
12 import (
13 "internal/abi"
14 "unsafe"
15 )
16
17 type instantiatedGroup[K comparable, V any] struct {
18 ctrls ctrlGroup
19 slots [abi.SwissMapGroupSlots]instantiatedSlot[K, V]
20 }
21
22 type instantiatedSlot[K comparable, V any] struct {
23 key K
24 elem V
25 }
26
27 func newTestMapType[K comparable, V any]() *abi.SwissMapType {
28 var m map[K]V
29 mTyp := abi.TypeOf(m)
30 omt := (*abi.OldMapType)(unsafe.Pointer(mTyp))
31
32 var grp instantiatedGroup[K, V]
33 var slot instantiatedSlot[K, V]
34
35 mt := &abi.SwissMapType{
36 Key: omt.Key,
37 Elem: omt.Elem,
38 Group: abi.TypeOf(grp),
39 Hasher: omt.Hasher,
40 SlotSize: unsafe.Sizeof(slot),
41 ElemOff: unsafe.Offsetof(slot.elem),
42 }
43 if omt.NeedKeyUpdate() {
44 mt.Flags |= abi.SwissMapNeedKeyUpdate
45 }
46 if omt.HashMightPanic() {
47 mt.Flags |= abi.SwissMapHashMightPanic
48 }
49 return mt
50 }
51
View as plain text