Fix murmurhash implementation (used for crafting) (#107)

Unaligned access does not work on ARM platforms, since data was declared u64*
the compiler assumed it was aligned, thus making the existing workaround useless.

Since this hash function is used for crafting, this commit fixes #106
master
sfan5 2018-03-30 22:32:56 +02:00 committed by MoNTE48
parent ec3b665a7f
commit 68bd3f0c9a
1 changed files with 8 additions and 5 deletions

View File

@ -60,19 +60,22 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed)
const int r = 47;
u64 h = seed ^ (len * m);
#if defined(__IOS__) // make sure memcpy() will not assume align
const u8 *data = (const u8 *)key;
const u8 *end = data + ( (unsigned int)len & ~7 );
#else
const u64 *data = (const u64 *)key;
const u64 *end = data + (len / 8);
#endif
while (data != end) {
u64 k;
#ifndef __IOS__
memcpy(&k, data, sizeof(u64));
#ifdef __IOS__
data += sizeof(u64);
#else
k = 0; // strange workaround for iOS
for (u8 i = 0; i < sizeof(u64); i++)
((char*) &k)[i] = data[i];
#endif
data++;
#endif
k *= m;
k ^= k >> r;