]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - util.c
The very aggressive -Ooverlap-strings
[xonotic/gmqcc.git] / util.c
diff --git a/util.c b/util.c
index 26803c898276897ed2d1b1abedf075be3d09c98e..b2b092d13828a7be9609fc08b68b380c46071f86 100644 (file)
--- a/util.c
+++ b/util.c
@@ -514,6 +514,40 @@ void *util_htget(hash_table_t *ht, const char *key) {
     return util_htgeth(ht, key, util_hthash(ht, key));
 }
 
+void *code_util_str_htgeth(hash_table_t *ht, const char *key, size_t bin) {
+    hash_node_t *pair;
+    size_t len, keylen;
+    int cmp;
+
+    keylen = strlen(key);
+
+    pair = ht->table[bin];
+    while (pair && pair->key) {
+        len = strlen(pair->key);
+        if (len < keylen) {
+            pair = pair->next;
+            continue;
+        }
+        if (keylen == len) {
+            cmp = strcmp(key, pair->key);
+            if (cmp == 0)
+                return pair->value;
+            if (cmp < 0)
+                return NULL;
+            pair = pair->next;
+            continue;
+        }
+        cmp = strcmp(key, pair->key + len - keylen);
+        if (cmp == 0) {
+            uintptr_t up = (uintptr_t)pair->value;
+            up += len - keylen;
+            return (void*)up;
+        }
+        pair = pair->next;
+    }
+    return NULL;
+}
+
 /*
  * Free all allocated data in a hashtable, this is quite the amount
  * of work.
@@ -595,12 +629,12 @@ static GMQCC_INLINE void mt_generate() {
      * to [0, MT_SIZE)  (634 iterations).
      */
     for (i = 0; i < MT_SPACE; ++i) {
-        y           = (0x800000000 & mt_state[i]) | (0x7FFFFFF & mt_state[i + 1]);
+        y           = (0x80000000 & mt_state[i]) | (0x7FFFFFF & mt_state[i + 1]);
         mt_state[i] = mt_state[i + MT_PERIOD] ^ (y >> 1) ^ matrix[y & 1];
 
         i ++; /* loop unroll */
 
-        y           = (0x800000000 & mt_state[i]) | (0x7FFFFFF & mt_state[i + 1]);
+        y           = (0x80000000 & mt_state[i]) | (0x7FFFFFF & mt_state[i + 1]);
         mt_state[i] = mt_state[i + MT_PERIOD] ^ (y >> 1) ^ matrix[y & 1];
     }