From: Jens Axboe Date: Wed, 23 Jan 2013 17:33:20 +0000 (-0700) Subject: axmap: improve axmap_find_first_free() X-Git-Tag: fio-2.0.14~100 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=731ef4c7c0aad1e6717e645595f3454d264b4f2f;p=fio.git axmap: improve axmap_find_first_free() Add a ret variable, saves a branch on return. Signed-off-by: Jens Axboe --- diff --git a/lib/axmap.c b/lib/axmap.c index 7351e297..df547f34 100644 --- a/lib/axmap.c +++ b/lib/axmap.c @@ -308,8 +308,9 @@ int axmap_isset(struct axmap *axmap, uint64_t bit_nr) static uint64_t axmap_find_first_free(struct axmap *axmap, unsigned int level, uint64_t index) { + uint64_t ret = -1ULL; unsigned long j; - int i, found = 0; + int i; /* * Start at the bottom, then converge towards first free bit at the top @@ -317,8 +318,11 @@ static uint64_t axmap_find_first_free(struct axmap *axmap, unsigned int level, for (i = level; i >= 0; i--) { struct axmap_level *al = &axmap->levels[i]; + /* + * Clear 'ret', this is a bug condition. + */ if (index >= al->map_size) { - index = -1ULL; + ret = -1ULL; break; } @@ -330,13 +334,12 @@ static uint64_t axmap_find_first_free(struct axmap *axmap, unsigned int level, * First free bit here is our index into the first * free bit at the next higher level */ - index = (j << UNIT_SHIFT) + ffz(al->map[j]); - found = 1; + ret = index = (j << UNIT_SHIFT) + ffz(al->map[j]); break; } } - return found ? index : (uint64_t) -1ULL; + return ret; } uint64_t axmap_first_free(struct axmap *axmap)