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

22 lines
375 B
Go
Raw Normal View History

2017-06-05 15:01:05 -07:00
// +build !appengine
2017-02-18 14:00:46 -08:00
package fasttemplate
import (
"reflect"
"unsafe"
)
func unsafeBytes2String(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
2020-09-04 14:29:13 -07:00
func unsafeString2Bytes(s string) (b []byte) {
2017-02-18 14:00:46 -08:00
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
2020-09-04 14:29:13 -07:00
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
bh.Data = sh.Data
bh.Cap = sh.Len
bh.Len = sh.Len
return b
2017-02-18 14:00:46 -08:00
}