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

18 lines
449 B
Go
Raw Permalink Normal View History

2024-09-26 01:59:44 +00:00
//go:build go1.20
// +build go1.20
package strconv
2024-09-26 01:59:44 +00:00
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 {
2024-09-26 01:59:44 +00:00
return unsafe.String(unsafe.SliceData(b), len(b))
}
// S2B converts string to a byte slice without memory allocation.
2024-09-26 01:59:44 +00:00
func S2B(s string) []byte {
return unsafe.Slice(unsafe.StringData(s), len(s))
}