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

23 lines
378 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))
}
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))
}