Merge 8c235252b6c626d755144a5e3b029cf65e83caf1 into 80cd679c43a3d6ed03957b6a3614f97d0af0751c

This commit is contained in:
anstns 2022-11-28 03:28:59 +00:00 committed by GitHub
commit d1dcaf4ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,21 +4,12 @@
package bytesconv
import (
"unsafe"
)
// StringToBytes converts string to byte slice without a memory allocation.
// StringToBytes converts string to byte slice
func StringToBytes(s string) []byte {
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Cap int
}{s, len(s)},
))
return []byte(s)
}
// BytesToString converts byte slice to string without a memory allocation.
// BytesToString converts byte slice to string
func BytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
return string(b)
}