Skip to content

Commit bea3453

Browse files
committed
Restore unsafe
1 parent 08eaa09 commit bea3453

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

hash.go

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

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

77
// MurmurHash3 implementation adapted from Sébastien Paolacci
@@ -31,11 +31,12 @@ 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-
j := 16 * i
37-
k1 := binary.LittleEndian.Uint64(p[j : j+8])
38-
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+
// 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])
3940
k1 *= c1
4041
k1 = (k1 << 31) | (k1 >> 33)
4142
k1 *= c2

0 commit comments

Comments
 (0)