lib/axmap: Optimize __axmap_set()
authorBart Van Assche <bart.vanassche@wdc.com>
Wed, 22 Aug 2018 20:22:12 +0000 (13:22 -0700)
committerBart Van Assche <bvanassche@acm.org>
Thu, 23 Aug 2018 01:59:24 +0000 (18:59 -0700)
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 <bart.vanassche@wdc.com>
lib/axmap.c

index 336d7048e07d3c607d7c61542c1200797e3c616b..e194e807ac542ee8068164e95f8977f7152b39cf 100644 (file)
@@ -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)