[PATCH 09/12] bitmap: optimize bitmap_remap() when 'new' is empty map

Yury Norov posted 12 patches 2 years, 3 months ago
[PATCH 09/12] bitmap: optimize bitmap_remap() when 'new' is empty map
Posted by Yury Norov 2 years, 3 months ago
When 'new' map is empty, we can skip remapping entirely and replace it
with bitmap_copy().

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 lib/bitmap.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index 2e8deeb8bf99..50385d61e6ea 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -1003,6 +1003,11 @@ void __bitmap_remap(unsigned long *dst, const unsigned long *src,
 	bitmap_zero(dst, nbits);
 
 	w = bitmap_weight(new, nbits);
+	if (w == 0) {
+		bitmap_copy(dst, src, nbits);
+		return;
+	}
+
 	for_each_set_bit(oldbit, src, nbits) {
 		int n = bitmap_pos_to_ord(old, oldbit, nbits);
 
-- 
2.39.2