apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r1237078 - /apr/apr/trunk/tables/apr_hash.c
Date Sat, 28 Jan 2012 15:54:22 GMT
Author: bojan
Date: Sat Jan 28 15:54:22 2012
New Revision: 1237078

URL: http://svn.apache.org/viewvc?rev=1237078&view=rev
Log:
Further improve hash randomisation:
Fix naming of a static function.
Randomise final hash produced by any hash function, using default hash
function and seed.

Modified:
    apr/apr/trunk/tables/apr_hash.c

Modified: apr/apr/trunk/tables/apr_hash.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/tables/apr_hash.c?rev=1237078&r1=1237077&r2=1237078&view=diff
==============================================================================
--- apr/apr/trunk/tables/apr_hash.c (original)
+++ apr/apr/trunk/tables/apr_hash.c Sat Jan 28 15:54:22 2012
@@ -106,7 +106,7 @@ APR_DECLARE(apr_hash_t *) apr_hash_make(
     ht->seed = (unsigned int)((now >> 32) ^ now ^ (apr_uintptr_t)pool ^
                               (apr_uintptr_t)ht ^ (apr_uintptr_t)&now) - 1;
     ht->array = alloc_array(ht, ht->max);
-    ht->hash_func = NULL;
+    ht->hash_func = apr_hashfunc_default;
 
     return ht;
 }
@@ -207,9 +207,8 @@ static void expand_array(apr_hash_t *ht)
     ht->max = new_max;
 }
 
-static unsigned int apr_hashfunc_default_internal(const char *char_key,
-                                                  apr_ssize_t *klen,
-                                                  unsigned int hash)
+static unsigned int hashfunc_default(const char *char_key, apr_ssize_t *klen,
+                                     unsigned int hash)
 {
     const unsigned char *key = (const unsigned char *)char_key;
     const unsigned char *p;
@@ -271,7 +270,7 @@ static unsigned int apr_hashfunc_default
 APR_DECLARE_NONSTD(unsigned int) apr_hashfunc_default(const char *char_key,
                                                       apr_ssize_t *klen)
 {
-    return apr_hashfunc_default_internal(char_key, klen, 0);
+    return hashfunc_default(char_key, klen, 0);
 }
 
 /*
@@ -290,11 +289,10 @@ static apr_hash_entry_t **find_entry(apr
 {
     apr_hash_entry_t **hep, *he;
     unsigned int hash;
+    apr_ssize_t hlen = sizeof(hash);
 
-    if (ht->hash_func)
-        hash = ht->hash_func(key, &klen);
-    else
-        hash = apr_hashfunc_default_internal(key, &klen, ht->seed);
+    hash = ht->hash_func(key, &klen);
+    hash = hashfunc_default((char *)&hash, &hlen, ht->seed);
 
     /* scan linked list */
     for (hep = &ht->array[hash & ht->max], he = *hep;
@@ -435,6 +433,7 @@ APR_DECLARE(apr_hash_t *) apr_hash_merge
     apr_hash_entry_t *iter;
     apr_hash_entry_t *ent;
     unsigned int i, j, k, hash;
+    apr_ssize_t hlen = sizeof(hash);
 
 #if APR_POOL_DEBUG
     /* we don't copy keys and values, so it's necessary that
@@ -484,11 +483,8 @@ APR_DECLARE(apr_hash_t *) apr_hash_merge
 
     for (k = 0; k <= overlay->max; k++) {
         for (iter = overlay->array[k]; iter; iter = iter->next) {
-            if (res->hash_func)
-                hash = res->hash_func(iter->key, &iter->klen);
-            else
-                hash = apr_hashfunc_default_internal(iter->key, &iter->klen,
-                                                     res->seed);
+            hash = res->hash_func(iter->key, &iter->klen);
+            hash = hashfunc_default((char*)&hash, &hlen, res->seed);
             i = hash & res->max;
             for (ent = res->array[i]; ent; ent = ent->next) {
                 if ((ent->klen == iter->klen) &&



Mime
View raw message