From: Lai Jiangshan Date: Mon, 17 Oct 2011 14:26:58 +0000 (-0400) Subject: compare hash value before call compare_fct() X-Git-Tag: v0.7.0~43^2~89 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=ae450da3b54fe3c8ea8fc92ec9a9ce2ad8f131cb;p=userspace-rcu.git compare hash value before call compare_fct() [ Edit by Mathieu Desnoyers: This is an optimisation that checks if the reverse hash value is equal before calling the comparison function. Given comparing a reverse hash is much faster than comparison, this accelarates the lookups and add. ] Signed-off-by: Lai Jiangshan Signed-off-by: Mathieu Desnoyers --- diff --git a/rculfhash.c b/rculfhash.c index 189f8c8..6e07878 100644 --- a/rculfhash.c +++ b/rculfhash.c @@ -892,6 +892,7 @@ struct cds_lfht_node *_cds_lfht_add(struct cds_lfht *ht, goto gc_node; if ((mode == ADD_UNIQUE || mode == ADD_REPLACE) && !is_dummy(next) + && clear_flag(iter)->p.reverse_hash == node->p.reverse_hash && !ht->compare_fct(node->key, node->key_len, clear_flag(iter)->key, clear_flag(iter)->key_len)) { @@ -1341,6 +1342,7 @@ void cds_lfht_lookup(struct cds_lfht *ht, void *key, size_t key_len, next = rcu_dereference(node->p.next); if (likely(!is_removed(next)) && !is_dummy(next) + && clear_flag(node)->p.reverse_hash == reverse_hash && likely(!ht->compare_fct(node->key, node->key_len, key, key_len))) { break; }