Skip to content

Commit 23d3a31

Browse files
committed
runtime: use unsafe.Slice for leveldb code
1 parent 0dfa57e commit 23d3a31

File tree

1 file changed

+1
-18
lines changed

1 file changed

+1
-18
lines changed

src/runtime/memhash_leveldb.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@ import (
1616
"unsafe"
1717
)
1818

19-
func ptrToSlice(ptr unsafe.Pointer, n uintptr) []byte {
20-
var p []byte
21-
22-
type _bslice struct {
23-
ptr *byte
24-
len uintptr
25-
cap uintptr
26-
}
27-
28-
pslice := (*_bslice)(unsafe.Pointer(&p))
29-
pslice.ptr = (*byte)(ptr)
30-
pslice.cap = n
31-
pslice.len = n
32-
33-
return p
34-
}
35-
3619
// leveldb hash
3720
func hash32(ptr unsafe.Pointer, n, seed uintptr) uint32 {
3821

@@ -41,7 +24,7 @@ func hash32(ptr unsafe.Pointer, n, seed uintptr) uint32 {
4124
m = 0xc6a4a793
4225
)
4326

44-
b := ptrToSlice(ptr, n)
27+
b := unsafe.Slice((*byte)(ptr), n)
4528

4629
h := uint32(lseed^seed) ^ uint32(uint(len(b))*uint(m))
4730

0 commit comments

Comments
 (0)