diff options
author | Bojan Smojver <bojan@apache.org> | 2012-01-28 03:00:40 +0000 |
---|---|---|
committer | Bojan Smojver <bojan@apache.org> | 2012-01-28 03:00:40 +0000 |
commit | edd4e239bb728bd23ad0db95bc52ce047de39b04 (patch) | |
tree | 5584fbc1132aae09318c90284e15c66237d21452 /tables | |
parent | ae02d04bde4a1a194a1ca512bb7afb22f23c35e5 (diff) | |
download | apr-edd4e239bb728bd23ad0db95bc52ce047de39b04.tar.gz |
Revert hash randomisation again. Elegant, but ultimately ineffective.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1236967 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tables')
-rw-r--r-- | tables/apr_hash.c | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/tables/apr_hash.c b/tables/apr_hash.c index 720cfdeab..d64e77941 100644 --- a/tables/apr_hash.c +++ b/tables/apr_hash.c @@ -18,7 +18,6 @@ #include "apr_general.h" #include "apr_pools.h" -#include "apr_time.h" #include "apr_hash.h" @@ -76,7 +75,7 @@ struct apr_hash_t { apr_pool_t *pool; apr_hash_entry_t **array; apr_hash_index_t iterator; /* For apr_hash_first(NULL, ...) */ - unsigned int count, max, seed; + unsigned int count, max; apr_hashfunc_t hash_func; apr_hash_entry_t *free; /* List of recycled entries */ }; @@ -96,18 +95,13 @@ static apr_hash_entry_t **alloc_array(apr_hash_t *ht, unsigned int max) APR_DECLARE(apr_hash_t *) apr_hash_make(apr_pool_t *pool) { apr_hash_t *ht; - apr_time_t now = apr_time_now(); - ht = apr_palloc(pool, sizeof(apr_hash_t)); ht->pool = pool; ht->free = NULL; ht->count = 0; ht->max = INITIAL_MAX; - 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 = apr_hashfunc_default; - return ht; } @@ -286,7 +280,7 @@ static apr_hash_entry_t **find_entry(apr_hash_t *ht, apr_hash_entry_t **hep, *he; unsigned int hash; - hash = ht->seed ^ ht->hash_func(key, &klen); + hash = ht->hash_func(key, &klen); /* scan linked list */ for (hep = &ht->array[hash & ht->max], he = *hep; @@ -328,7 +322,6 @@ APR_DECLARE(apr_hash_t *) apr_hash_copy(apr_pool_t *pool, ht->free = NULL; ht->count = orig->count; ht->max = orig->max; - ht->seed = orig->seed; ht->hash_func = orig->hash_func; ht->array = (apr_hash_entry_t **)((char *)ht + sizeof(apr_hash_t)); @@ -426,7 +419,7 @@ APR_DECLARE(apr_hash_t *) apr_hash_merge(apr_pool_t *p, apr_hash_entry_t *new_vals = NULL; apr_hash_entry_t *iter; apr_hash_entry_t *ent; - unsigned int i, j, k, hash; + unsigned int i,j,k; #if APR_POOL_DEBUG /* we don't copy keys and values, so it's necessary that @@ -454,7 +447,6 @@ APR_DECLARE(apr_hash_t *) apr_hash_merge(apr_pool_t *p, if (base->count + overlay->count > res->max) { res->max = res->max * 2 + 1; } - res->seed = base->seed; res->array = alloc_array(res, res->max); if (base->count + overlay->count) { new_vals = apr_palloc(p, sizeof(apr_hash_entry_t) * @@ -476,12 +468,7 @@ APR_DECLARE(apr_hash_t *) apr_hash_merge(apr_pool_t *p, for (k = 0; k <= overlay->max; k++) { for (iter = overlay->array[k]; iter; iter = iter->next) { - if (res->hash_func == overlay->hash_func) - hash = iter->hash ^ overlay->seed; - else - hash = res->hash_func(iter->key, &iter->klen); - hash = res->seed ^ hash; - i = hash & res->max; + i = iter->hash & res->max; for (ent = res->array[i]; ent; ent = ent->next) { if ((ent->klen == iter->klen) && (memcmp(ent->key, iter->key, iter->klen) == 0)) { @@ -499,7 +486,7 @@ APR_DECLARE(apr_hash_t *) apr_hash_merge(apr_pool_t *p, new_vals[j].klen = iter->klen; new_vals[j].key = iter->key; new_vals[j].val = iter->val; - new_vals[j].hash = hash; + new_vals[j].hash = iter->hash; new_vals[j].next = res->array[i]; res->array[i] = &new_vals[j]; res->count++; |