From 7a04f99c72af668d374c13c5a52c7d57c0484d6a Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 29 Feb 2024 17:17:13 +0200 Subject: [PATCH] lib/fastnum: use unsafe.Slice() instead of deprecated reflect.SliceHeader --- lib/fastnum/fastnum.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/fastnum/fastnum.go b/lib/fastnum/fastnum.go index 524098bb2..34966947b 100644 --- a/lib/fastnum/fastnum.go +++ b/lib/fastnum/fastnum.go @@ -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 (