diff options
author | David Garcia Quintas <dgq@google.com> | 2017-12-04 16:25:01 -0800 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2017-12-04 16:25:01 -0800 |
commit | 6667f15d8e4ea915bd64647e2c7949d37d1bad91 (patch) | |
tree | de1f6de5029d7c51ee369efa5294e00736014597 /src/core/lib/support/murmur_hash.cc | |
parent | 0f91e513d9dc9bee529701ba254933eb7be07b38 (diff) | |
parent | 6fa206de8f8a1444fff19a84945a424c0cabb41c (diff) |
Merge branch 'master' of github.com:grpc/grpc into backoff_cpp
Diffstat (limited to 'src/core/lib/support/murmur_hash.cc')
-rw-r--r-- | src/core/lib/support/murmur_hash.cc | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/core/lib/support/murmur_hash.cc b/src/core/lib/support/murmur_hash.cc index 4e08579a1d..2f0e71a53c 100644 --- a/src/core/lib/support/murmur_hash.cc +++ b/src/core/lib/support/murmur_hash.cc @@ -30,22 +30,19 @@ (h) ^= (h) >> 16; uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) { - const uint8_t* data = (const uint8_t*)key; - const size_t nblocks = len / 4; - int i; - uint32_t h1 = seed; uint32_t k1; const uint32_t c1 = 0xcc9e2d51; const uint32_t c2 = 0x1b873593; - const uint32_t* blocks = ((const uint32_t*)key) + nblocks; - const uint8_t* tail = (const uint8_t*)(data + nblocks * 4); + const uint8_t* keyptr = (const uint8_t*)key; + const size_t bsize = sizeof(k1); + const size_t nblocks = len / bsize; /* body */ - for (i = -(int)nblocks; i; i++) { - memcpy(&k1, blocks + i, sizeof(uint32_t)); + for (size_t i = 0; i < nblocks; i++, keyptr += bsize) { + memcpy(&k1, keyptr, bsize); k1 *= c1; k1 = ROTL32(k1, 15); @@ -61,13 +58,13 @@ uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) { /* tail */ switch (len & 3) { case 3: - k1 ^= ((uint32_t)tail[2]) << 16; + k1 ^= ((uint32_t)keyptr[2]) << 16; /* fallthrough */ case 2: - k1 ^= ((uint32_t)tail[1]) << 8; + k1 ^= ((uint32_t)keyptr[1]) << 8; /* fallthrough */ case 1: - k1 ^= tail[0]; + k1 ^= keyptr[0]; k1 *= c1; k1 = ROTL32(k1, 15); k1 *= c2; |