1
0
mirror of https://github.com/fumiama/go-registry.git synced 2026-06-29 23:30:35 +08:00
This commit is contained in:
源文雨
2022-10-28 11:25:34 +08:00
parent 680755130a
commit 42411b3d58
7 changed files with 96 additions and 102 deletions

View File

@@ -9,9 +9,9 @@ import "unsafe"
// Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the
// data it references will not be garbage collected.
type slice struct {
Data unsafe.Pointer
Len int
Cap int
data unsafe.Pointer
len int
cap int
}
// BytesToString 没有内存开销的转换
@@ -23,8 +23,8 @@ func BytesToString(b []byte) string {
func StringToBytes(s string) (b []byte) {
bh := (*slice)(unsafe.Pointer(&b))
sh := (*slice)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Len = sh.Len
bh.Cap = sh.Len
bh.data = sh.data
bh.len = sh.len
bh.cap = sh.len
return b
}