forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/valyala/fasttemplate/unsafe.go

32 lines
406 B
Go
Raw Normal View History

2024-06-14 08:41:36 +00:00
//go:build !appengine
2024-02-18 10:42:21 +00:00
// +build !appengine
package fasttemplate
import (
"reflect"
"unsafe"
)
func unsafeBytes2String(b []byte) string {
2024-02-18 10:42:21 +00:00
return *(*string)(unsafe.Pointer(&b))
2024-02-18 10:42:21 +00:00
}
func unsafeString2Bytes(s string) (b []byte) {
2024-02-18 10:42:21 +00:00
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
2024-02-18 10:42:21 +00:00
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
2024-02-18 10:42:21 +00:00
bh.Data = sh.Data
2024-02-18 10:42:21 +00:00
bh.Cap = sh.Len
2024-02-18 10:42:21 +00:00
bh.Len = sh.Len
2024-02-18 10:42:21 +00:00
return b
2024-02-18 10:42:21 +00:00
}