Skip to content

Commit

Permalink
Remove unsafe, alignment not guaranteed
Browse files Browse the repository at this point in the history
  • Loading branch information
korthaj committed May 9, 2017
1 parent 8cbd4b0 commit a6906f1
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions hash.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bloom

import (
"unsafe"
"encoding/binary"
)

// MurmurHash3 implementation adapted from Sébastien Paolacci
Expand Down Expand Up @@ -31,12 +31,9 @@ func (d *digest) bmix(p []byte) (tail []byte) {
h1, h2 := d.h1, d.h2
nblocks := len(p) / 16
for i := 0; i < nblocks; i++ {
t := (*[2]uint64)(unsafe.Pointer(&p[i*16]))
k1, k2 := t[0], t[1]
// Without unsafe:
// j := 16 * i
// k1 := binary.LittleEndian.Uint64(p[j : j+8])
// k2 := binary.LittleEndian.Uint64(p[j+8 : j+16])
j := 16 * i
k1 := binary.LittleEndian.Uint64(p[j : j+8])
k2 := binary.LittleEndian.Uint64(p[j+8 : j+16])
k1 *= c1
k1 = (k1 << 31) | (k1 >> 33)
k1 *= c2
Expand Down

0 comments on commit a6906f1

Please sign in to comment.