[PATCH 08/12] bitmap: optiimze bitmap_bitremap()
From: Yury Norov
Date: Mon Aug 28 2023 - 14:44:53 EST
When 'new' map is empty, we can skip remapping entirely and return
the old bit.
Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
---
lib/bitmap.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 9ecdc74cb6b4..2e8deeb8bf99 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -1017,12 +1017,17 @@ EXPORT_SYMBOL(__bitmap_remap);
int __bitmap_bitremap(int oldbit, const unsigned long *old,
const unsigned long *new, int bits)
{
- int w = bitmap_weight(new, bits);
- int n = bitmap_pos_to_ord(old, oldbit, bits);
- if (n < 0 || w == 0)
+ int w, n;
+
+ w = bitmap_weight(new, bits);
+ if (w == 0)
+ return oldbit;
+
+ n = bitmap_pos_to_ord(old, oldbit, bits);
+ if (n < 0)
return oldbit;
- else
- return find_nth_bit(new, bits, n % w);
+
+ return find_nth_bit(new, bits, n % w);
}
EXPORT_SYMBOL(__bitmap_bitremap);
--
2.39.2