[PATCH 09/12] bitmap: optimize bitmap_remap() when 'new' is empty map
From: Yury Norov
Date: Mon Aug 28 2023 - 14:44:55 EST
When 'new' map is empty, we can skip remapping entirely and replace it
with bitmap_copy().
Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
---
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