lib/find: optimize find_*_bit_wrap
authorYury Norov <yury.norov@gmail.com>
Sat, 28 Oct 2023 19:05:29 +0000 (12:05 -0700)
committerYury Norov <yury.norov@gmail.com>
Sun, 3 Dec 2023 18:28:17 +0000 (10:28 -0800)
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>
include/linux/find.h

index af63ae5b90137ab3d1d11d6369babe95800a8ddb..c69598e383c1618fbbdd99e252f70c2cacfd72df 100644 (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);