2 Star 4 Fork 0

fufuok/utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
convert_go119.go 376 Bytes
一键复制 编辑 原始数据 按行查看 历史
//go:build !go1.20
// +build !go1.20
package utils
import (
"unsafe"
)
// S2B StringToBytes converts string to byte slice without a memory allocation.
// Ref: gin
func S2B(s string) []byte {
return *(*[]byte)(unsafe.Pointer(
&struct {
string
Cap int
}{s, len(s)},
))
}
// B2S BytesToString
func B2S(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fufuok/utils.git
git@gitee.com:fufuok/utils.git
fufuok
utils
utils
master

搜索帮助