Improve performance of tokenization and parsing

This commit is contained in:
gingerBill
2020-05-27 18:23:37 +01:00
parent 876820789e
commit 1a0614b0d7
10 changed files with 367 additions and 214 deletions
+33
View File
@@ -223,3 +223,36 @@ void MurmurHash3_x86_128(void const *key, isize len, u32 seed, void *out) {
// }
gb_internal gb_inline u32 murmur_32_scramble(u32 k) {
k *= 0xcc9e2d51;
k = (k << 15) | (k >> 17);
k *= 0x1b873593;
return k;
}
u32 murmur3_32(u8 const *key, isize len, u32 seed) {
u32 h = seed;
u32 k;
for (size_t i = len >> 2; i; i--) {
memcpy(&k, key, sizeof(u32));
key += sizeof(u32);
h ^= murmur_32_scramble(k);
h = (h << 13) | (h >> 19);
h = h * 5 + 0xe6546b64;
}
k = 0;
for (size_t i = len & 3; i; i--) {
k <<= 8;
k |= key[i - 1];
}
h ^= murmur_32_scramble(k);
h ^= len;
h ^= h >> 16;
h *= 0x85ebca6b;
h ^= h >> 13;
h *= 0xc2b2ae35;
h ^= h >> 16;
return h;
}