lib/bitmap.c: bitmap_[empty,full]: remove code duplication
authorYury Norov <yury.norov@gmail.com>
Thu, 16 Apr 2015 19:44:00 +0000 (12:44 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 17 Apr 2015 13:03:56 +0000 (09:03 -0400)
bitmap_empty() has its own implementation.  But it's clearly as simple as:

find_first_bit(src, nbits) == nbits

The same is true for 'bitmap_full'.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
Cc: George Spelvin <linux@horizon.com>
Cc: Alexey Klimov <klimov.linux@gmail.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/bitmap.h
lib/bitmap.c

index be4fa5ddf36cb84c7061c5ff22c9d11b6e4cedd8..ea17cca9e6852f982b1f98a5a06f863de7324e61 100644 (file)
@@ -283,16 +283,16 @@ static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
 {
        if (small_const_nbits(nbits))
                return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
-       else
-               return __bitmap_empty(src, nbits);
+
+       return find_first_bit(src, nbits) == nbits;
 }
 
 static inline int bitmap_full(const unsigned long *src, unsigned int nbits)
 {
        if (small_const_nbits(nbits))
                return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
-       else
-               return __bitmap_full(src, nbits);
+
+       return find_first_zero_bit(src, nbits) == nbits;
 }
 
 static inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
index d456f4c15a9f999eb49d00485840ad61fcb3fbae..64c0926f5dd8e5801a2f8609721ae67e60d3e3e2 100644 (file)
  * for the best explanations of this ordering.
  */
 
-int __bitmap_empty(const unsigned long *bitmap, unsigned int bits)
-{
-       unsigned int k, lim = bits/BITS_PER_LONG;
-       for (k = 0; k < lim; ++k)
-               if (bitmap[k])
-                       return 0;
-
-       if (bits % BITS_PER_LONG)
-               if (bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
-                       return 0;
-
-       return 1;
-}
-EXPORT_SYMBOL(__bitmap_empty);
-
-int __bitmap_full(const unsigned long *bitmap, unsigned int bits)
-{
-       unsigned int k, lim = bits/BITS_PER_LONG;
-       for (k = 0; k < lim; ++k)
-               if (~bitmap[k])
-                       return 0;
-
-       if (bits % BITS_PER_LONG)
-               if (~bitmap[k] & BITMAP_LAST_WORD_MASK(bits))
-                       return 0;
-
-       return 1;
-}
-EXPORT_SYMBOL(__bitmap_full);
-
 int __bitmap_equal(const unsigned long *bitmap1,
                const unsigned long *bitmap2, unsigned int bits)
 {