1 // This file will only be included to the build if neither
2 // easyjson_nounsafe nor appengine build tag is set. See README notes
5 //+build !easyjson_nounsafe
15 // bytesToStr creates a string pointing at the slice to avoid copying.
17 // Warning: the string returned by the function should be used with care, as the whole input data
18 // chunk may be either blocked from being freed by GC because of a single string or the buffer.Data
19 // may be garbage-collected even when the string exists.
20 func bytesToStr(data []byte) string {
21 h := (*reflect.SliceHeader)(unsafe.Pointer(&data))
22 shdr := reflect.StringHeader{Data: h.Data, Len: h.Len}
23 return *(*string)(unsafe.Pointer(&shdr))