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

23 lines
378 B
Go
Raw Normal View History

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