Skip to content

Commit 3988ce1

Browse files
committed
update string to bytes converter
1 parent 9ef61d6 commit 3988ce1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ func b2s(b []byte) string {
1111
return *(*string)(unsafe.Pointer(&b))
1212
}
1313

14-
func s2b(s string) []byte {
14+
func s2b(s string) (b []byte) {
1515
strh := (*reflect.StringHeader)(unsafe.Pointer(&s))
16-
var sh reflect.SliceHeader
16+
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
1717
sh.Data = strh.Data
1818
sh.Len = strh.Len
1919
sh.Cap = strh.Len
20-
return *(*[]byte)(unsafe.Pointer(&sh))
20+
return b
2121
}

0 commit comments

Comments
 (0)