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
  • Loading branch information
inliquid committed Aug 26, 2024
1 parent 8974b8b commit 7020e36
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions wasm/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ package wasm
import "C"

import (
"reflect"
"unsafe"
)

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 7020e36

Please sign in to comment.