From 7d409960c92e794a9bd12b60c13ff178d86c185a Mon Sep 17 00:00:00 2001 From: Xuefer Date: Thu, 1 Mar 2007 10:55:04 +0000 Subject: [PATCH] merged from 1.2: fix for #71, fix inode hvalue issue by better hashing git-svn-id: svn://svn.lighttpd.net/xcache/trunk@359 c26eb9a1-5813-0410-bd6c-c2e55f420ca7 --- xcache.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/xcache.c b/xcache.c index cbb2863..0f5e257 100644 --- a/xcache.c +++ b/xcache.c @@ -728,6 +728,16 @@ static int xc_stat(const char *filename, const char *include_path, struct stat * #define HASH_STR_L(s, l) HASH_STR_S(s, l + 1) #define HASH_STR(s) HASH_STR_L(s, strlen(s) + 1) #define HASH_NUM(n) HASH(n) +static inline xc_hash_value_t xc_hash_fold(xc_hash_value_t hvalue, const xc_hash_t *hasher) /* {{{ fold hash bits as needed */ +{ + xc_hash_value_t folded = 0; + while (hvalue) { + folded ^= (hvalue & hasher->mask); + hvalue >>= hasher->bits; + } + return folded; +} +/* }}} */ static inline xc_hash_value_t xc_entry_hash_name(xc_entry_t *xce TSRMLS_DC) /* {{{ */ { return UNISW(NOTHING, UG(unicode) ? HASH_USTR_L(xce->name_type, xce->name.uni.val, xce->name.uni.len) :) @@ -842,10 +852,9 @@ stat_done: xce->name.str.len = strlen(filename); hv = xc_entry_hash_php(xce TSRMLS_CC); - cacheid = (hv & xc_php_hcache.mask); + cacheid = xc_hash_fold(hv, &xc_php_hcache); xce->cache = xc_php_caches[cacheid]; - hv >>= xc_php_hcache.bits; - xce->hvalue = (hv & xc_php_hentry.mask); + xce->hvalue = xc_hash_fold(hv, &xc_php_hentry); xce->type = XC_TYPE_PHP; return SUCCESS;