Skip to content

Commit 0dfa57e

Browse files
committed
runtime: use unsafe.Slice in tsip code
1 parent 2f9e39e commit 0dfa57e

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

src/runtime/memhash_tsip.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,6 @@ import (
1515
"unsafe"
1616
)
1717

18-
func ptrToSlice(ptr unsafe.Pointer, n uintptr) []byte {
19-
var p []byte
20-
21-
type _bslice struct {
22-
ptr *byte
23-
len uintptr
24-
cap uintptr
25-
}
26-
27-
pslice := (*_bslice)(unsafe.Pointer(&p))
28-
pslice.ptr = (*byte)(ptr)
29-
pslice.cap = n
30-
pslice.len = n
31-
32-
return p
33-
}
34-
3518
type sip struct {
3619
v0, v1 uint64
3720
}
@@ -45,8 +28,7 @@ func (s *sip) round() {
4528
}
4629

4730
func hash64(ptr unsafe.Pointer, n uintptr, seed uintptr) uint64 {
48-
49-
p := ptrToSlice(ptr, n)
31+
p := unsafe.Slice((*byte)(ptr), n)
5032

5133
k0 := uint64(seed)
5234
k1 := uint64(0)
@@ -117,9 +99,7 @@ func (s *sip32) round() {
11799
}
118100

119101
func hash32(ptr unsafe.Pointer, n uintptr, seed uintptr) uint32 {
120-
// TODO(dgryski): replace this messiness with unsafe.Slice when we can use 1.17 features
121-
122-
p := ptrToSlice(ptr, n)
102+
p := unsafe.Slice((*byte)(ptr), n)
123103

124104
k0 := uint32(seed)
125105
k1 := uint32(seed >> 32)

0 commit comments

Comments
 (0)