lib/fastnum: use unsafe.Slice() instead of deprecated reflect.SliceHeader

This commit is contained in:
Aliaksandr Valialkin 2024-02-29 17:17:13 +02:00
parent a3cf3d7de1
commit 7a04f99c72
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -2,7 +2,6 @@ package fastnum
import (
"bytes"
"reflect"
"unsafe"
)
@ -124,20 +123,12 @@ func isFloat64Data(a, data []float64) bool {
return true
}
func int64ToByteSlice(a []int64) (b []byte) {
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh.Data = uintptr(unsafe.Pointer(&a[0]))
sh.Len = len(a) * int(unsafe.Sizeof(a[0]))
sh.Cap = sh.Len
return
func int64ToByteSlice(a []int64) []byte {
return unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(a))), len(a)*8)
}
func float64ToByteSlice(a []float64) (b []byte) {
sh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh.Data = uintptr(unsafe.Pointer(&a[0]))
sh.Len = len(a) * int(unsafe.Sizeof(a[0]))
sh.Cap = sh.Len
return
func float64ToByteSlice(a []float64) []byte {
return unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(a))), len(a)*8)
}
var (