go
/
misc
1
0
Fork 0
misc/strutil/trick.go

15 lines
354 B
Go

package strutil
import (
"unsafe"
)
// B2S converts byte slice to a string without memory allocation.
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
//
// Note it may break if string and/or slice header will change
// in the future go versions.
func B2S(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}