1
0
mirror of https://github.com/fumiama/go-base16384.git synced 2026-06-05 00:32:52 +08:00

优化slice

This commit is contained in:
源文雨
2022-12-14 10:40:41 +08:00
parent 75ee4a090e
commit e8419f8b75
2 changed files with 6 additions and 6 deletions

View File

@@ -13,8 +13,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
}

View File

@@ -9,7 +9,7 @@ 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
}