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