1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| func unsafeAdd(base unsafe.Pointer, offset uintptr) unsafe.Pointer { return unsafe.Pointer(uintptr(base) + offset) }
func unsafeIndex(base unsafe.Pointer, offset uintptr, elemsz uintptr, n int) unsafe.Pointer { return unsafe.Pointer(uintptr(base) + offset + uintptr(n)*elemsz) }
func unsafeByteSlice(base unsafe.Pointer, offset uintptr, i, j int) []byte { return (*[maxAllocSize]byte)(unsafeAdd(base, offset))[i:j:j] }
func unsafeSlice(slice, data unsafe.Pointer, len int) { s := (*reflect.SliceHeader)(slice) s.Data = uintptr(data) s.Cap = len s.Len = len }
|