Skip to content

Commit

Permalink
Merge pull request #1489 from siyuebin11/patch-1
Browse files Browse the repository at this point in the history
Solve the problem of function parameters being recycled by GC
  • Loading branch information
colin-si authored Sep 13, 2024
2 parents 452bfcb + bd045ba commit 43004ff
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ func BytesToStringWithNoCopy(bytes []byte) string {
}

func StringToBytesWithNoCopy(s string) []byte {
x := (*[2]uintptr)(unsafe.Pointer(&s))
h := [3]uintptr{x[0], x[1], x[1]}
return *(*[]byte)(unsafe.Pointer(&h))
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Cap int
}{s, len(s)},
))
}

func ListToMap(list []string) map[string]struct{} {
Expand Down

0 comments on commit 43004ff

Please sign in to comment.