Skip to content

Commit

Permalink
Use unsafe.Slice instead of reflect.SliceHeader to build byte slice
Browse files Browse the repository at this point in the history
Signed-off-by: Alex In <[email protected]>
  • Loading branch information
inliquid committed Aug 24, 2024
1 parent 8974b8b commit f012adc
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions wasm/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ import (
)

func PtrToByte(ptr, size uint32) []byte {
var b []byte
s := (*reflect.SliceHeader)(unsafe.Pointer(&b))
s.Len = uintptr(size)
s.Cap = uintptr(size)
s.Data = uintptr(ptr)
b := unsafe.Slice((*byte)(unsafe.Pointer(uintptr(ptr))), size)

return b
}

Expand Down

0 comments on commit f012adc

Please sign in to comment.