Files
fasthttp/s2b_old.go
T
tyltr dd1f3b97e5 update build tag (#1695)
* update  go.sum

* update build tag
2024-01-18 04:41:42 +01:00

22 lines
442 B
Go

//go:build !go1.20 && !go1.21
package fasthttp
import (
"reflect"
"unsafe"
)
// s2b converts string to a byte slice without memory allocation.
//
// Note it may break if string and/or slice header will change
// in the future go versions.
func s2b(s string) (b []byte) {
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Cap = sh.Len
bh.Len = sh.Len
return b
}