From ae450da3b54fe3c8ea8fc92ec9a9ce2ad8f131cb Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Mon, 17 Oct 2011 10:26:58 -0400 Subject: [PATCH] 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 --- rculfhash.c | 2 ++ 1 file changed, 2 insertions(+) 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; } -- 2.34.1