mirror of
https://github.com/fumiama/go-base16384.git
synced 2026-06-19 02:13:24 +08:00
优化slice
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
6
slice.go
6
slice.go
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user