Skip to content

Commit

Permalink
rhashtable: Eliminate unnecessary branch in rht_key_hashfn
Browse files Browse the repository at this point in the history
When rht_key_hashfn is called from rhashtable itself and params
is equal to ht->p, there is no point in checking params.key_len
and falling back to ht->p.key_len.

For some reason gcc couldn't figure out that params is the same
as ht->p.  So let's help it by only checking params.key_len when
it's a constant.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Herbert Xu authored and David S. Miller committed Mar 24, 2015
1 parent d88252f commit de91b25
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/linux/rhashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ static inline unsigned int rht_key_hashfn(
struct rhashtable *ht, const struct bucket_table *tbl,
const void *key, const struct rhashtable_params params)
{
return rht_bucket_index(tbl, params.hashfn(key, params.key_len ?:
ht->p.key_len,
/* params must be equal to ht->p if it isn't constant. */
unsigned key_len = __builtin_constant_p(params.key_len) ?
(params.key_len ?: ht->p.key_len) :
params.key_len;

return rht_bucket_index(tbl, params.hashfn(key, key_len,
tbl->hash_rnd));
}

Expand Down

0 comments on commit de91b25

Please sign in to comment.