mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
update util_unsafe.go to use simpler, yet still safe, cast
This commit is contained in:
parent
813d953eeb
commit
2141537561
1 changed files with 3 additions and 6 deletions
|
|
@ -4,7 +4,6 @@ package util
|
|||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
|
@ -14,13 +13,11 @@ func BytesToReadOnlyString(b []byte) string {
|
|||
}
|
||||
|
||||
// StringToReadOnlyBytes returns bytes converted from given string.
|
||||
func StringToReadOnlyBytes(s string) []byte {
|
||||
b := make([]byte, 0)
|
||||
func StringToReadOnlyBytes(s string) (bs []byte) {
|
||||
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
||||
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bh := (*reflect.SliceHeader)(unsafe.Pointer(&bs))
|
||||
bh.Data = sh.Data
|
||||
bh.Cap = sh.Len
|
||||
bh.Len = sh.Len
|
||||
runtime.KeepAlive(s)
|
||||
return b
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue