mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
Optimize TouUnsafeBytes to make it leaner, more standards-compliant and (#5880)
slightly faster.
This commit is contained in:
parent
b9b4e859be
commit
8266b77d0e
1 changed files with 1 additions and 7 deletions
|
@ -2,7 +2,6 @@ package bytesutil
|
|||
|
||||
import (
|
||||
"math/bits"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -72,10 +71,5 @@ func ToUnsafeString(b []byte) string {
|
|||
//
|
||||
// The returned byte slice is valid only until s is reachable and unmodified.
|
||||
func ToUnsafeBytes(s string) (b []byte) {
|
||||
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
||||
slh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
slh.Data = sh.Data
|
||||
slh.Len = sh.Len
|
||||
slh.Cap = sh.Len
|
||||
return b
|
||||
return unsafe.Slice(unsafe.StringData(s), len(s))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue