mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/bytesutil: use unsafe.String instead of unsafe conversion of slice header to string header
This commit is contained in:
parent
e959f54351
commit
38e0397ebd
1 changed files with 2 additions and 2 deletions
|
@ -64,12 +64,12 @@ func roundToNearestPow2(n int) int {
|
|||
//
|
||||
// The returned string is valid only until b is reachable and unmodified.
|
||||
func ToUnsafeString(b []byte) string {
|
||||
return *(*string)(unsafe.Pointer(&b))
|
||||
return unsafe.String(unsafe.SliceData(b), len(b))
|
||||
}
|
||||
|
||||
// ToUnsafeBytes converts s to a byte slice without memory allocations.
|
||||
//
|
||||
// The returned byte slice is valid only until s is reachable and unmodified.
|
||||
func ToUnsafeBytes(s string) (b []byte) {
|
||||
func ToUnsafeBytes(s string) []byte {
|
||||
return unsafe.Slice(unsafe.StringData(s), len(s))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue