]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - hash.c
For now I'll just disable this
[xonotic/gmqcc.git] / hash.c
diff --git a/hash.c b/hash.c
index 221c650f422871ce86255b332ab3f0f199d89fd6..46edc743b26cbeab70ff4ebdd06f7b29793244df 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012, 2013
+ * Copyright (C) 2012, 2013, 2014
  *     Dale Weiler
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy of
@@ -22,6 +22,7 @@
  */
 #include "gmqcc.h"
 #include <limits.h>
+#include <string.h>
 
 #if defined(_MSC_VER)
 #   define HASH_ROTL32(X, Y) _rotl((X), (Y))
@@ -118,7 +119,6 @@ static GMQCC_FORCEINLINE uint32_t hash_murmur_mix32(uint32_t hash) {
         H  = HASH_ROTL32(H, 13);                       \
         H  = H * 5 + 0xE6546B64;                       \
     } while (0)
-
 #define HASH_MURMUR_BYTES(COUNT, H, C, N, PTR, LENGTH) \
     do {                                               \
         int i = COUNT;                                 \
@@ -132,6 +132,13 @@ static GMQCC_FORCEINLINE uint32_t hash_murmur_mix32(uint32_t hash) {
             }                                          \
         }                                              \
     } while (0)
+#define HASH_MURMUR_TAIL(P, Z, H, C, N, PTR, LEN)      \
+    do {                                               \
+        LEN -= LEN/4*4;                                \
+        HASH_MURMUR_BYTES(LEN, H, C, N, PTR, LEN);     \
+        *P = H;                                        \
+        *Z = ((C) & ~0xFF) | (N);                      \
+    } while (0)
 
 #if PLATFORM_BYTE_ORDER == GMQCC_BYTE_ORDER_LITTLE
 static GMQCC_FORCEINLINE void hash_murmur_process(uint32_t *ph1, uint32_t *carry, const void *key, int length) {
@@ -151,13 +158,7 @@ static GMQCC_FORCEINLINE void hash_murmur_process(uint32_t *ph1, uint32_t *carry
         uint32_t k1 = HASH_MURMUR_SAFEREAD(ptr);
         HASH_MURMUR_BLOCK(h1, k1);
     }
-
-    length -= length/4*4;
-
-    HASH_MURMUR_BYTES(length, h1, c, n, ptr, length);
-
-    *ph1   = h1;
-    *carry = (c & ~0xFF) | n;
+    HASH_MURMUR_TAIL(ph1, carry, h1, c, n, ptr, length);
 }
 #else
 static GMQCC_FORCEINLINE void hash_murmur_process(uint32_t *ph1, uint32_t *carry, const void *key, int length) {
@@ -196,12 +197,7 @@ static GMQCC_FORCEINLINE void hash_murmur_process(uint32_t *ph1, uint32_t *carry
         NEXT(3, 8,  24);
         #undef NEXT
     }
-    length -= length/4*4;
-
-    HASH_MURMUR_BYTES(length, h1, c, n, ptr, length);
-
-    *ph1   = h1;
-    *carry = (c & ~0xFF) | n;
+    HASH_MURMUR_TAIL(ph1, carry, h1, c, n, ptr, length);
 }
 #endif
 
@@ -229,6 +225,7 @@ static GMQCC_FORCEINLINE uint32_t hash_murmur(const void *GMQCC_RESTRICT key, si
 }
 
 size_t hash(const char *key) {
+#if 0
     const char   *s = key;
     const char   *a = s;
     const size_t *w;
@@ -241,4 +238,16 @@ size_t hash(const char *key) {
     for (s = (const char *)w; *s; s++);
 
     return hash_murmur((const void *)key, s-a);
+#else
+    return hash_murmur((const void *)key, strlen(key));
+#endif
 }
+
+#undef HASH_ROTL32
+#undef HASH_MURMUR_MASK1
+#undef HASH_MURMUR_MASK2
+#undef HASH_MURMUR_SEED
+#undef HASH_MURMUR_SAFEREAD
+#undef HASH_MURMUR_BLOCK
+#undef HASH_MURMUR_BYTES
+#undef HASH_MURMUR_TAIL