lib/find: optimize find_*_bit_wrap

When an offset is 0, there's no need to search a bitmap from the
beginning after the 1st search failed, because each bit has already
been tested.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
This commit is contained in:
Yury Norov 2023-10-28 12:05:29 -07:00
parent 92697139b0
commit 27c82f14e6

View File

@ -405,7 +405,7 @@ unsigned long find_next_and_bit_wrap(const unsigned long *addr1,
{
unsigned long bit = find_next_and_bit(addr1, addr2, size, offset);
if (bit < size)
if (bit < size || offset == 0)
return bit;
bit = find_first_and_bit(addr1, addr2, offset);
@ -427,7 +427,7 @@ unsigned long find_next_bit_wrap(const unsigned long *addr,
{
unsigned long bit = find_next_bit(addr, size, offset);
if (bit < size)
if (bit < size || offset == 0)
return bit;
bit = find_first_bit(addr, offset);