Skip to content

Commit a6906f1

Browse files
committed
Remove unsafe, alignment not guaranteed
1 parent 8cbd4b0 commit a6906f1

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

hash.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package bloom
22

33
import (
4-
"unsafe"
4+
"encoding/binary"
55
)
66

77
// MurmurHash3 implementation adapted from Sébastien Paolacci
@@ -31,12 +31,9 @@ func (d *digest) bmix(p []byte) (tail []byte) {
3131
h1, h2 := d.h1, d.h2
3232
nblocks := len(p) / 16
3333
for i := 0; i < nblocks; i++ {
34-
t := (*[2]uint64)(unsafe.Pointer(&p[i*16]))
35-
k1, k2 := t[0], t[1]
36-
// Without unsafe:
37-
// j := 16 * i
38-
// k1 := binary.LittleEndian.Uint64(p[j : j+8])
39-
// k2 := binary.LittleEndian.Uint64(p[j+8 : j+16])
34+
j := 16 * i
35+
k1 := binary.LittleEndian.Uint64(p[j : j+8])
36+
k2 := binary.LittleEndian.Uint64(p[j+8 : j+16])
4037
k1 *= c1
4138
k1 = (k1 << 31) | (k1 >> 33)
4239
k1 *= c2

0 commit comments

Comments
 (0)