Skip to content

Commit e05514a

Browse files
committed
Remove unsafe optimization
1 parent da6d587 commit e05514a

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

hash.go

Lines changed: 6 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,11 @@ 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 on a little endian machine:
37-
// j := 16 * i
38-
// k1 := binary.LittleEndian.Uint64(p[j : j+8])
39-
// k2 := binary.LittleEndian.Uint64(p[j+8 : j+16])
34+
//t := (*[2]uint64)(unsafe.Pointer(&p[i*16]))
35+
//k1, k2 := t[0], t[1]
36+
j := 16 * i
37+
k1 := binary.LittleEndian.Uint64(p[j : j+8])
38+
k2 := binary.LittleEndian.Uint64(p[j+8 : j+16])
4039
k1 *= c1
4140
k1 = (k1 << 31) | (k1 >> 33)
4241
k1 *= c2

0 commit comments

Comments
 (0)