vmail/vendor/github.com/valyala/fasttemplate/unsafe.go

22 lines
375 B
Go
Raw Normal View History

2020-07-07 00:13:18 +02:00
// +build !appengine
package fasttemplate
import (
"reflect"
"unsafe"
)
func unsafeBytes2String(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
2021-04-04 21:56:48 +02:00
func unsafeString2Bytes(s string) (b []byte) {
2020-07-07 00:13:18 +02:00
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
2021-04-04 21:56:48 +02:00
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
bh.Data = sh.Data
bh.Cap = sh.Len
bh.Len = sh.Len
return b
2020-07-07 00:13:18 +02:00
}