From 1cf97788d4e533e4216160c2715f14596106e1e5 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 22 Aug 2018 13:22:12 -0700 Subject: [PATCH] lib/axmap: Optimize __axmap_set() Since it is guaranteed that nr_bits <= BLOCKS_PER_UNIT and since axmap_set_fn() needs to be called only once to set that number of bits, remove the loop from __axmap_set(). Signed-off-by: Bart Van Assche --- lib/axmap.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/axmap.c b/lib/axmap.c index 336d7048..e194e807 100644 --- a/lib/axmap.c +++ b/lib/axmap.c @@ -268,29 +268,16 @@ static bool axmap_set_fn(struct axmap_level *al, unsigned long offset, static void __axmap_set(struct axmap *axmap, uint64_t bit_nr, struct axmap_set_data *data) { - unsigned int set_bits, nr_bits = data->nr_bits; + unsigned int nr_bits = data->nr_bits; if (bit_nr > axmap->nr_bits) return; else if (bit_nr + nr_bits > axmap->nr_bits) nr_bits = axmap->nr_bits - bit_nr; - set_bits = 0; - while (nr_bits) { - axmap_handler(axmap, bit_nr, axmap_set_fn, data); - set_bits += data->set_bits; + assert(nr_bits <= BLOCKS_PER_UNIT); - if (!data->set_bits || - data->set_bits != (BLOCKS_PER_UNIT - nr_bits)) - break; - - nr_bits -= data->set_bits; - bit_nr += data->set_bits; - - data->nr_bits = nr_bits; - } - - data->set_bits = set_bits; + axmap_handler(axmap, bit_nr, axmap_set_fn, data); } void axmap_set(struct axmap *axmap, uint64_t bit_nr) -- 2.25.1