mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 03:24:00 +00:00
runtime: use unsafe.Slice in tsip code
This commit is contained in:
committed by
Damian Gryski
parent
2f9e39e21c
commit
0dfa57ea04
@@ -15,23 +15,6 @@ import (
|
|||||||
"unsafe"
|
"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 {
|
type sip struct {
|
||||||
v0, v1 uint64
|
v0, v1 uint64
|
||||||
}
|
}
|
||||||
@@ -45,8 +28,7 @@ func (s *sip) round() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func hash64(ptr unsafe.Pointer, n uintptr, seed uintptr) uint64 {
|
func hash64(ptr unsafe.Pointer, n uintptr, seed uintptr) uint64 {
|
||||||
|
p := unsafe.Slice((*byte)(ptr), n)
|
||||||
p := ptrToSlice(ptr, n)
|
|
||||||
|
|
||||||
k0 := uint64(seed)
|
k0 := uint64(seed)
|
||||||
k1 := uint64(0)
|
k1 := uint64(0)
|
||||||
@@ -117,9 +99,7 @@ func (s *sip32) round() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func hash32(ptr unsafe.Pointer, n uintptr, seed uintptr) uint32 {
|
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 := unsafe.Slice((*byte)(ptr), n)
|
||||||
|
|
||||||
p := ptrToSlice(ptr, n)
|
|
||||||
|
|
||||||
k0 := uint32(seed)
|
k0 := uint32(seed)
|
||||||
k1 := uint32(seed >> 32)
|
k1 := uint32(seed >> 32)
|
||||||
|
|||||||
Reference in New Issue
Block a user