mojoshader_preprocessor.c
changeset 729 92cc053fbf75
parent 727 6978fac0fa31
child 746 6b368eeaa3fc
--- a/mojoshader_preprocessor.c	Tue Mar 24 01:37:22 2009 -0400
+++ b/mojoshader_preprocessor.c	Sun Mar 29 22:27:07 2009 -0400
@@ -383,19 +383,25 @@
 
 // Preprocessor define hashtable stuff...
 
-static unsigned char hash_define(const char *sym)
+// this is djb's xor hashing function.
+static inline uint32 hash_string_djbxor(const char *sym)
 {
-    unsigned char retval = 0;
+    register uint32 hash = 5381;
     while (*sym)
-        retval += *(sym++);
-    return retval;
+        hash = ((hash << 5) + hash) ^ *(sym++);
+    return hash;
+} // hash_string_djbxor
+
+static inline uint8 hash_define(const char *sym)
+{
+    return (uint8) hash_string_djbxor(sym);
 } // hash_define
 
 
 static int add_define(Context *ctx, const char *sym, const char *val,
                       char **parameters, unsigned int paramcount)
 {
-    const unsigned char hash = hash_define(sym);
+    const uint8 hash = hash_define(sym);
     Define *bucket = ctx->define_hashtable[hash];
     while (bucket)
     {
@@ -435,7 +441,7 @@
 
 static int remove_define(Context *ctx, const char *sym)
 {
-    const unsigned char hash = hash_define(sym);
+    const uint8 hash = hash_define(sym);
     Define *bucket = ctx->define_hashtable[hash];
     Define *prev = NULL;
     while (bucket)
@@ -459,7 +465,7 @@
 
 static const Define *find_define(Context *ctx, const char *sym)
 {
-    const unsigned char hash = hash_define(sym);
+    const uint8 hash = hash_define(sym);
     Define *bucket = ctx->define_hashtable[hash];
     while (bucket)
     {