feat: super 包添加 []byte、string 零拷贝转换函数

This commit is contained in:
kercylan98 2023-07-20 19:32:58 +08:00
parent b6f28dd743
commit 506e0f2ee4
1 changed files with 11 additions and 0 deletions

11
utils/super/unsafe.go Normal file
View File

@ -0,0 +1,11 @@
package super
import "unsafe"
func StringToBytes(s string) []byte {
return unsafe.Slice(unsafe.StringData(s), len(s))
}
func BytesToString(b []byte) string {
return unsafe.String(&b[0], len(b))
}