[PATCH 08/12] bitmap: optiimze bitmap_bitremap()

Yury Norov posted 12 patches 2 years, 3 months ago
[PATCH 08/12] bitmap: optiimze bitmap_bitremap()
Posted by Yury Norov 2 years, 3 months ago
When 'new' map is empty, we can skip remapping entirely and return
the old bit.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 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