Skip to content

Commit 3b5e861

Browse files
authored
fix compile error from #2572 (#2600)
1 parent 7742ff5 commit 3b5e861

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

internal/bytesconv/bytesconv.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
package bytesconv
66

77
import (
8-
"reflect"
98
"unsafe"
109
)
1110

1211
// StringToBytes converts string to byte slice without a memory allocation.
1312
func StringToBytes(s string) (b []byte) {
14-
sh := *(*reflect.StringHeader)(unsafe.Pointer(&s))
15-
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
16-
bh.Data, bh.Len, bh.Cap = sh.Data, sh.Len, sh.Len
17-
return b
13+
return *(*[]byte)(unsafe.Pointer(
14+
&struct {
15+
string
16+
Cap int
17+
}{s, len(s)},
18+
))
1819
}
1920

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

0 commit comments

Comments
 (0)