rculfhash: Simplify lookup_bucket()
authorLai Jiangshan <laijs@cn.fujitsu.com>
Mon, 17 Oct 2011 14:19:10 +0000 (10:19 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 17 Oct 2011 14:19:10 +0000 (10:19 -0400)
They are the same, but I don't think the compiler can optimize it.

And it also helps for understanding the following code.

[ Edit by Mathieu Desnoyers:
  - Add a comment that describes the equivalence between get_count_order
    and fls for this lookup of index + 1. ]

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rculfhash.c

index d733d6bd53da2cab4b849e343656ce53df4326f7..189f8c831237edfe205c6461babadb765b537285 100644 (file)
@@ -724,7 +724,12 @@ struct _cds_lfht_node *lookup_bucket(struct cds_lfht *ht, unsigned long size,
 
        assert(size > 0);
        index = hash & (size - 1);
-       order = get_count_order_ulong(index + 1);
+       /*
+        * equivalent to get_count_order_ulong(index + 1), but optimizes
+        * away the non-existing 0 special-case for
+        * get_count_order_ulong.
+        */
+       order = fls_ulong(index);
 
        dbg_printf("lookup hash %lu index %lu order %lu aridx %lu\n",
                   hash, index, order, index & (!order ? 0 : ((1UL << (order - 1)) - 1)));
This page took 0.026021 seconds and 4 git commands to generate.