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 GroupSize: unsafe.Sizeof(grp),
42 ElemOff: unsafe.Offsetof(slot.elem),
43 }
44 if omt.NeedKeyUpdate() {
45 mt.Flags |= abi.SwissMapNeedKeyUpdate
46 }
47 if omt.HashMightPanic() {
48 mt.Flags |= abi.SwissMapHashMightPanic
49 }
50 return mt
51 }
52
View as plain text