aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/modern-go/reflect2/unsafe_map.go
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2023-12-29 21:31:53 +0100
committerLibravatar Rutger Broekhoff2023-12-29 21:31:53 +0100
commit404aeae4545d2426c089a5f8d5e82dae56f5212b (patch)
tree2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/modern-go/reflect2/unsafe_map.go
parent209d8b0187ed025dec9ac149ebcced3462877bff (diff)
downloadgitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz
gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip
Make Nix builds work
Diffstat (limited to 'vendor/github.com/modern-go/reflect2/unsafe_map.go')
-rw-r--r--vendor/github.com/modern-go/reflect2/unsafe_map.go130
1 files changed, 130 insertions, 0 deletions
diff --git a/vendor/github.com/modern-go/reflect2/unsafe_map.go b/vendor/github.com/modern-go/reflect2/unsafe_map.go
new file mode 100644
index 0000000..37872da
--- /dev/null
+++ b/vendor/github.com/modern-go/reflect2/unsafe_map.go
@@ -0,0 +1,130 @@
1package reflect2
2
3import (
4 "reflect"
5 "unsafe"
6)
7
8type UnsafeMapType struct {
9 unsafeType
10 pKeyRType unsafe.Pointer
11 pElemRType unsafe.Pointer
12}
13
14func newUnsafeMapType(cfg *frozenConfig, type1 reflect.Type) MapType {
15 return &UnsafeMapType{
16 unsafeType: *newUnsafeType(cfg, type1),
17 pKeyRType: unpackEFace(reflect.PtrTo(type1.Key())).data,
18 pElemRType: unpackEFace(reflect.PtrTo(type1.Elem())).data,
19 }
20}
21
22func (type2 *UnsafeMapType) IsNil(obj interface{}) bool {
23 if obj == nil {
24 return true
25 }
26 objEFace := unpackEFace(obj)
27 assertType("Type.IsNil argument 1", type2.ptrRType, objEFace.rtype)
28 return type2.UnsafeIsNil(objEFace.data)
29}
30
31func (type2 *UnsafeMapType) UnsafeIsNil(ptr unsafe.Pointer) bool {
32 if ptr == nil {
33 return true
34 }
35 return *(*unsafe.Pointer)(ptr) == nil
36}
37
38func (type2 *UnsafeMapType) LikePtr() bool {
39 return true
40}
41
42func (type2 *UnsafeMapType) Indirect(obj interface{}) interface{} {
43 objEFace := unpackEFace(obj)
44 assertType("MapType.Indirect argument 1", type2.ptrRType, objEFace.rtype)
45 return type2.UnsafeIndirect(objEFace.data)
46}
47
48func (type2 *UnsafeMapType) UnsafeIndirect(ptr unsafe.Pointer) interface{} {
49 return packEFace(type2.rtype, *(*unsafe.Pointer)(ptr))
50}
51
52func (type2 *UnsafeMapType) Key() Type {
53 return type2.cfg.Type2(type2.Type.Key())
54}
55
56func (type2 *UnsafeMapType) MakeMap(cap int) interface{} {
57 return packEFace(type2.ptrRType, type2.UnsafeMakeMap(cap))
58}
59
60func (type2 *UnsafeMapType) UnsafeMakeMap(cap int) unsafe.Pointer {
61 m := makeMapWithSize(type2.rtype, cap)
62 return unsafe.Pointer(&m)
63}
64
65func (type2 *UnsafeMapType) SetIndex(obj interface{}, key interface{}, elem interface{}) {
66 objEFace := unpackEFace(obj)
67 assertType("MapType.SetIndex argument 1", type2.ptrRType, objEFace.rtype)
68 keyEFace := unpackEFace(key)
69 assertType("MapType.SetIndex argument 2", type2.pKeyRType, keyEFace.rtype)
70 elemEFace := unpackEFace(elem)
71 assertType("MapType.SetIndex argument 3", type2.pElemRType, elemEFace.rtype)
72 type2.UnsafeSetIndex(objEFace.data, keyEFace.data, elemEFace.data)
73}
74
75func (type2 *UnsafeMapType) UnsafeSetIndex(obj unsafe.Pointer, key unsafe.Pointer, elem unsafe.Pointer) {
76 mapassign(type2.rtype, *(*unsafe.Pointer)(obj), key, elem)
77}
78
79func (type2 *UnsafeMapType) TryGetIndex(obj interface{}, key interface{}) (interface{}, bool) {
80 objEFace := unpackEFace(obj)
81 assertType("MapType.TryGetIndex argument 1", type2.ptrRType, objEFace.rtype)
82 keyEFace := unpackEFace(key)
83 assertType("MapType.TryGetIndex argument 2", type2.pKeyRType, keyEFace.rtype)
84 elemPtr := type2.UnsafeGetIndex(objEFace.data, keyEFace.data)
85 if elemPtr == nil {
86 return nil, false
87 }
88 return packEFace(type2.pElemRType, elemPtr), true
89}
90
91func (type2 *UnsafeMapType) GetIndex(obj interface{}, key interface{}) interface{} {
92 objEFace := unpackEFace(obj)
93 assertType("MapType.GetIndex argument 1", type2.ptrRType, objEFace.rtype)
94 keyEFace := unpackEFace(key)
95 assertType("MapType.GetIndex argument 2", type2.pKeyRType, keyEFace.rtype)
96 elemPtr := type2.UnsafeGetIndex(objEFace.data, keyEFace.data)
97 return packEFace(type2.pElemRType, elemPtr)
98}
99
100func (type2 *UnsafeMapType) UnsafeGetIndex(obj unsafe.Pointer, key unsafe.Pointer) unsafe.Pointer {
101 return mapaccess(type2.rtype, *(*unsafe.Pointer)(obj), key)
102}
103
104func (type2 *UnsafeMapType) Iterate(obj interface{}) MapIterator {
105 objEFace := unpackEFace(obj)
106 assertType("MapType.Iterate argument 1", type2.ptrRType, objEFace.rtype)
107 return type2.UnsafeIterate(objEFace.data)
108}
109
110type UnsafeMapIterator struct {
111 *hiter
112 pKeyRType unsafe.Pointer
113 pElemRType unsafe.Pointer
114}
115
116func (iter *UnsafeMapIterator) HasNext() bool {
117 return iter.key != nil
118}
119
120func (iter *UnsafeMapIterator) Next() (interface{}, interface{}) {
121 key, elem := iter.UnsafeNext()
122 return packEFace(iter.pKeyRType, key), packEFace(iter.pElemRType, elem)
123}
124
125func (iter *UnsafeMapIterator) UnsafeNext() (unsafe.Pointer, unsafe.Pointer) {
126 key := iter.key
127 elem := iter.value
128 mapiternext(iter.hiter)
129 return key, elem
130}