...
1
2
3
4
5
6
7 package codec
8
9 import (
10 "reflect"
11 _ "runtime"
12 "unsafe"
13 )
14
15 var unsafeZeroArr [1024]byte
16
17
18
19
20 func unsafeGrowslice(typ unsafe.Pointer, old unsafeSlice, cap, incr int) (v unsafeSlice) {
21 size := rtsize2(typ)
22 if size == 0 {
23 return unsafeSlice{unsafe.Pointer(&unsafeZeroArr[0]), old.Len, cap + incr}
24 }
25 newcap := int(growCap(uint(cap), uint(size), uint(incr)))
26 v = unsafeSlice{Data: newarray(typ, newcap), Len: old.Len, Cap: newcap}
27 if old.Len > 0 {
28 typedslicecopy(typ, v, old)
29 }
30
31 return
32 }
33
34
35
36
37
38
39
40
41
42
43 func mapStoresElemIndirect(elemsize uintptr) bool { return false }
44
45 func mapSet(m, k, v reflect.Value, _ mapKeyFastKind, _, valIsRef bool) {
46 var urv = (*unsafeReflectValue)(unsafe.Pointer(&k))
47 var kptr = unsafeMapKVPtr(urv)
48 urv = (*unsafeReflectValue)(unsafe.Pointer(&v))
49 var vtyp = urv.typ
50 var vptr = unsafeMapKVPtr(urv)
51
52 urv = (*unsafeReflectValue)(unsafe.Pointer(&m))
53 mptr := rvRefPtr(urv)
54
55 vvptr := mapassign(urv.typ, mptr, kptr)
56 typedmemmove(vtyp, vvptr, vptr)
57 }
58
59 func mapGet(m, k, v reflect.Value, _ mapKeyFastKind, _, valIsRef bool) (_ reflect.Value) {
60 var urv = (*unsafeReflectValue)(unsafe.Pointer(&k))
61 var kptr = unsafeMapKVPtr(urv)
62 urv = (*unsafeReflectValue)(unsafe.Pointer(&m))
63 mptr := rvRefPtr(urv)
64
65 vvptr, ok := mapaccess2(urv.typ, mptr, kptr)
66
67 if !ok {
68 return
69 }
70
71 urv = (*unsafeReflectValue)(unsafe.Pointer(&v))
72
73 if helperUnsafeDirectAssignMapEntry || valIsRef {
74 urv.ptr = vvptr
75 } else {
76 typedmemmove(urv.typ, urv.ptr, vvptr)
77 }
78
79 return v
80 }
81
View as plain text