rhashtable: abstract out function to get hash

Split out most of rht_key_hashfn which is calculating the hash into
its own function. This way the hash function can be called separately to
get the hash value.

Acked-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Tom Herbert <tom@quantonium.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Tom Herbert 2017-12-04 10:31:43 -08:00 коммит произвёл David S. Miller
Родитель 2db54b475a
Коммит 2b86093135
1 изменённых файлов: 18 добавлений и 10 удалений

Просмотреть файл

@ -240,34 +240,42 @@ static inline unsigned int rht_bucket_index(const struct bucket_table *tbl,
return (hash >> RHT_HASH_RESERVED_SPACE) & (tbl->size - 1); return (hash >> RHT_HASH_RESERVED_SPACE) & (tbl->size - 1);
} }
static inline unsigned int rht_key_hashfn( static inline unsigned int rht_key_get_hash(struct rhashtable *ht,
struct rhashtable *ht, const struct bucket_table *tbl, const void *key, const struct rhashtable_params params,
const void *key, const struct rhashtable_params params) unsigned int hash_rnd)
{ {
unsigned int hash; unsigned int hash;
/* params must be equal to ht->p if it isn't constant. */ /* params must be equal to ht->p if it isn't constant. */
if (!__builtin_constant_p(params.key_len)) if (!__builtin_constant_p(params.key_len))
hash = ht->p.hashfn(key, ht->key_len, tbl->hash_rnd); hash = ht->p.hashfn(key, ht->key_len, hash_rnd);
else if (params.key_len) { else if (params.key_len) {
unsigned int key_len = params.key_len; unsigned int key_len = params.key_len;
if (params.hashfn) if (params.hashfn)
hash = params.hashfn(key, key_len, tbl->hash_rnd); hash = params.hashfn(key, key_len, hash_rnd);
else if (key_len & (sizeof(u32) - 1)) else if (key_len & (sizeof(u32) - 1))
hash = jhash(key, key_len, tbl->hash_rnd); hash = jhash(key, key_len, hash_rnd);
else else
hash = jhash2(key, key_len / sizeof(u32), hash = jhash2(key, key_len / sizeof(u32), hash_rnd);
tbl->hash_rnd);
} else { } else {
unsigned int key_len = ht->p.key_len; unsigned int key_len = ht->p.key_len;
if (params.hashfn) if (params.hashfn)
hash = params.hashfn(key, key_len, tbl->hash_rnd); hash = params.hashfn(key, key_len, hash_rnd);
else else
hash = jhash(key, key_len, tbl->hash_rnd); hash = jhash(key, key_len, hash_rnd);
} }
return hash;
}
static inline unsigned int rht_key_hashfn(
struct rhashtable *ht, const struct bucket_table *tbl,
const void *key, const struct rhashtable_params params)
{
unsigned int hash = rht_key_get_hash(ht, key, params, tbl->hash_rnd);
return rht_bucket_index(tbl, hash); return rht_bucket_index(tbl, hash);
} }