well-goknown/vendor/github.com/savsgio/gotils/strconv/strconv_120.go

18 lines
449 B
Go
Raw Normal View History

//go:build go1.20
// +build go1.20
package strconv
import "unsafe"
// B2S converts byte slice to a string without memory allocation.
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
func B2S(b []byte) string {
return unsafe.String(unsafe.SliceData(b), len(b))
}
// S2B converts string to a byte slice without memory allocation.
func S2B(s string) []byte {
return unsafe.Slice(unsafe.StringData(s), len(s))
}