1
0
mirror of https://github.com/fumiama/go-base16384.git synced 2026-06-19 10:26:33 +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) { func StringToBytes(s string) (b []byte) {
bh := (*slice)(unsafe.Pointer(&b)) bh := (*slice)(unsafe.Pointer(&b))
sh := (*slice)(unsafe.Pointer(&s)) sh := (*slice)(unsafe.Pointer(&s))
bh.Data = sh.Data bh.data = sh.data
bh.Len = sh.Len bh.len = sh.len
bh.Cap = sh.Len bh.cap = sh.len
return b return b
} }

View File

@@ -9,7 +9,7 @@ import "unsafe"
// Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the // Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the
// data it references will not be garbage collected. // data it references will not be garbage collected.
type slice struct { type slice struct {
Data unsafe.Pointer data unsafe.Pointer
Len int len int
Cap int cap int
} }