Skip to content

Commit

Permalink
fix compile error from #2572 (#2600)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkerou committed Jan 3, 2021
1 parent 7742ff5 commit 3b5e861
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/bytesconv/bytesconv.go
Expand Up @@ -5,16 +5,17 @@
package bytesconv

import (
"reflect"
"unsafe"
)

// StringToBytes converts string to byte slice without a memory allocation.
func StringToBytes(s string) (b []byte) {
sh := *(*reflect.StringHeader)(unsafe.Pointer(&s))
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
bh.Data, bh.Len, bh.Cap = sh.Data, sh.Len, sh.Len
return b
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Cap int
}{s, len(s)},
))
}

// BytesToString converts byte slice to string without a memory allocation.
Expand Down

0 comments on commit 3b5e861

Please sign in to comment.