mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 00:13:43 +00:00
runtime: use unsafe.Slice for leveldb code
This commit is contained in:
committed by
Damian Gryski
parent
0dfa57ea04
commit
23d3a31107
@@ -16,23 +16,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
|
|
||||||
}
|
|
||||||
|
|
||||||
// leveldb hash
|
// leveldb hash
|
||||||
func hash32(ptr unsafe.Pointer, n, seed uintptr) uint32 {
|
func hash32(ptr unsafe.Pointer, n, seed uintptr) uint32 {
|
||||||
|
|
||||||
@@ -41,7 +24,7 @@ func hash32(ptr unsafe.Pointer, n, seed uintptr) uint32 {
|
|||||||
m = 0xc6a4a793
|
m = 0xc6a4a793
|
||||||
)
|
)
|
||||||
|
|
||||||
b := ptrToSlice(ptr, n)
|
b := unsafe.Slice((*byte)(ptr), n)
|
||||||
|
|
||||||
h := uint32(lseed^seed) ^ uint32(uint(len(b))*uint(m))
|
h := uint32(lseed^seed) ^ uint32(uint(len(b))*uint(m))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user