1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-07 04:02:58 +03:00

Fold in possible use of FNV if desired

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@998949 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jim Jagielski
2010-09-20 14:51:19 +00:00
parent 15734940ad
commit 1d50e028df
2 changed files with 17 additions and 9 deletions

View File

@@ -810,7 +810,7 @@ ap_proxy_buckets_lifetime_transform(request_rec *r, apr_bucket_brigade *from,
* @return hash as unsigned int * @return hash as unsigned int
*/ */
typedef enum { PROXY_HASHFUNC_PROXY, PROXY_HASHFUNC_APR } proxy_hash_t; typedef enum { PROXY_HASHFUNC_DEFAULT, PROXY_HASHFUNC_APR, PROXY_HASHFUNC_FNV } proxy_hash_t;
PROXY_DECLARE(unsigned int) PROXY_DECLARE(unsigned int)
ap_proxy_hashfunc(const char *str, proxy_hash_t method); ap_proxy_hashfunc(const char *str, proxy_hash_t method);

View File

@@ -1481,7 +1481,7 @@ PROXY_DECLARE(const char *) ap_proxy_add_worker_wid(proxy_worker **worker,
(*worker)->flush_packets = flush_off; (*worker)->flush_packets = flush_off;
(*worker)->flush_wait = PROXY_FLUSH_WAIT; (*worker)->flush_wait = PROXY_FLUSH_WAIT;
(*worker)->smax = -1; (*worker)->smax = -1;
(*worker)->our_hash = ap_proxy_hashfunc((*worker)->name, PROXY_HASHFUNC_PROXY); (*worker)->our_hash = ap_proxy_hashfunc((*worker)->name, PROXY_HASHFUNC_DEFAULT);
(*worker)->apr_hash = ap_proxy_hashfunc((*worker)->name, PROXY_HASHFUNC_APR); (*worker)->apr_hash = ap_proxy_hashfunc((*worker)->name, PROXY_HASHFUNC_APR);
(*worker)->cp = NULL; (*worker)->cp = NULL;
(*worker)->mutex = NULL; (*worker)->mutex = NULL;
@@ -2766,10 +2766,10 @@ ap_proxy_buckets_lifetime_transform(request_rec *r, apr_bucket_brigade *from,
/* /*
* Provide a string hashing function for the proxy. * Provide a string hashing function for the proxy.
* We offer 2 method: one is the APR model but we * We offer 2 methods: one is the APR model but we
* also provide our own, based on SDBM. The reason * also provide our own, based on either FNV or SDBM.
* is in case we want to use both to ensure no * The reason is in case we want to use both to ensure no
* collisions * collisions.
*/ */
PROXY_DECLARE(unsigned int) PROXY_DECLARE(unsigned int)
ap_proxy_hashfunc(const char *str, proxy_hash_t method) ap_proxy_hashfunc(const char *str, proxy_hash_t method)
@@ -2777,7 +2777,16 @@ ap_proxy_hashfunc(const char *str, proxy_hash_t method)
if (method == PROXY_HASHFUNC_APR) { if (method == PROXY_HASHFUNC_APR) {
apr_ssize_t slen = strlen(str); apr_ssize_t slen = strlen(str);
return apr_hashfunc_default(str, &slen); return apr_hashfunc_default(str, &slen);
} else { } else if (method == PROXY_HASHFUNC_FNV) {
/* FNV model */
unsigned int hash;
const unsigned int fnv_prime = 0x811C9DC5;
for (hash = 0; *str; str++) {
hash *= fnv_prime;
hash ^= (*str);
}
return hash;
} else { /* method == PROXY_HASHFUNC_DEFAULT */
/* SDBM model */ /* SDBM model */
unsigned int hash; unsigned int hash;
for (hash = 0; *str; str++) { for (hash = 0; *str; str++) {
@@ -2785,5 +2794,4 @@ ap_proxy_hashfunc(const char *str, proxy_hash_t method)
} }
return hash; return hash;
} }
} }