]> git.mxchange.org Git - simgear.git/blobdiff - simgear/nasal/hash.c
Olaf Flebbe:
[simgear.git] / simgear / nasal / hash.c
index 3b02bc8f7e80414bc512f4c2414ab68d195d4f4a..55946535fe921fbbfcfea8f630a54df1309bf031 100644 (file)
@@ -49,7 +49,7 @@ static unsigned int hashcolumn(struct HashRec* h, naRef key)
     return (HASH_MAGIC * hashcode(key)) >> (32 - h->lgalloced);
 }
 
-static struct HashRec* realloc(struct naHash* hash)
+static struct HashRec* hashrealloc(struct naHash* hash)
 {
     struct HashRec *h, *h0 = hash->rec;
     int lga, cols, need = h0 ? h0->size - h0->dels : MIN_HASH_SIZE;
@@ -118,7 +118,7 @@ static struct HashNode* find(struct naHash* hash, naRef key)
 static void tmpStr(naRef* out, struct naStr* str, char* key)
 {
     str->len = 0;
-    str->data = key;
+    str->data = (unsigned char*)key;
     while(key[str->len]) str->len++;
     *out = naNil();
     out->ref.ptr.str = str;
@@ -170,8 +170,8 @@ void naHash_newsym(struct naHash* hash, naRef* sym, naRef* val)
 {
     int col;
     struct HashRec* h = hash->rec;
-    if(!h || h->size >= 1<<h->lgalloced)
-        h = realloc(hash);
+    while(!h || h->size >= 1<<h->lgalloced)
+        h = hashrealloc(hash);
     col = (HASH_MAGIC * sym->ref.ptr.str->hashcode) >> (32 - h->lgalloced);
     INSERT(h, *sym, *val, col);
 }
@@ -198,7 +198,7 @@ void naHash_set(naRef hash, naRef key, naRef val)
     if((n = find(hash.ref.ptr.hash, key))) { n->val = val; return; }
     h = hash.ref.ptr.hash->rec;
     while(!h || h->size >= 1<<h->lgalloced)
-        h = realloc(hash.ref.ptr.hash);
+        h = hashrealloc(hash.ref.ptr.hash);
     col = hashcolumn(h, key);
     INSERT(h, key, val, hashcolumn(h, key));
     chkcycle(h->table[col], h->size - h->dels);