From 1f71b072da3b95eff956b718989272b44d5eacd6 Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Fri, 18 Oct 2024 10:25:04 -0700 Subject: [PATCH 1/2] runtime: use unsafe.Slice in tsip code --- src/runtime/memhash_tsip.go | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/runtime/memhash_tsip.go b/src/runtime/memhash_tsip.go index a8829e0527..607055bd50 100644 --- a/src/runtime/memhash_tsip.go +++ b/src/runtime/memhash_tsip.go @@ -15,23 +15,6 @@ import ( "unsafe" ) -func ptrToSlice(ptr unsafe.Pointer, n uintptr) []byte { - var p []byte - - type _bslice struct { - ptr *byte - len uintptr - cap uintptr - } - - pslice := (*_bslice)(unsafe.Pointer(&p)) - pslice.ptr = (*byte)(ptr) - pslice.cap = n - pslice.len = n - - return p -} - type sip struct { v0, v1 uint64 } @@ -45,8 +28,7 @@ func (s *sip) round() { } func hash64(ptr unsafe.Pointer, n uintptr, seed uintptr) uint64 { - - p := ptrToSlice(ptr, n) + p := unsafe.Slice((*byte)(ptr), n) k0 := uint64(seed) k1 := uint64(0) @@ -117,9 +99,7 @@ func (s *sip32) round() { } func hash32(ptr unsafe.Pointer, n uintptr, seed uintptr) uint32 { - // TODO(dgryski): replace this messiness with unsafe.Slice when we can use 1.17 features - - p := ptrToSlice(ptr, n) + p := unsafe.Slice((*byte)(ptr), n) k0 := uint32(seed) k1 := uint32(seed >> 32) From 5bb63d309275581ae94d18096106dc315d83167f Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Fri, 18 Oct 2024 10:26:26 -0700 Subject: [PATCH 2/2] runtime: use unsafe.Slice for leveldb code --- src/runtime/memhash_leveldb.go | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/runtime/memhash_leveldb.go b/src/runtime/memhash_leveldb.go index f57c9cf93e..2e7557bb3f 100644 --- a/src/runtime/memhash_leveldb.go +++ b/src/runtime/memhash_leveldb.go @@ -16,23 +16,6 @@ import ( "unsafe" ) -func ptrToSlice(ptr unsafe.Pointer, n uintptr) []byte { - var p []byte - - type _bslice struct { - ptr *byte - len uintptr - cap uintptr - } - - pslice := (*_bslice)(unsafe.Pointer(&p)) - pslice.ptr = (*byte)(ptr) - pslice.cap = n - pslice.len = n - - return p -} - // leveldb hash func hash32(ptr unsafe.Pointer, n, seed uintptr) uint32 { @@ -41,7 +24,7 @@ func hash32(ptr unsafe.Pointer, n, seed uintptr) uint32 { m = 0xc6a4a793 ) - b := ptrToSlice(ptr, n) + b := unsafe.Slice((*byte)(ptr), n) h := uint32(lseed^seed) ^ uint32(uint(len(b))*uint(m))