[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230903095059.2683850-1-visitorckw@gmail.com>
Date: Sun, 3 Sep 2023 17:50:59 +0800
From: Kuan-Wei Chiu <visitorckw@...il.com>
To: song@...nel.org
Cc: linux-raid@...r.kernel.org, linux-kernel@...r.kernel.org,
Kuan-Wei Chiu <visitorckw@...il.com>
Subject: [PATCH] md/raid5: eliminate if-statements in cmp_stripe()
Replace the conditional statements in the cmp_stripe() function with a
branchless version to improve code readability and potentially enhance
performance. The new code calculates the result using a subtraction of
comparison results, making it more concise and avoiding conditional
branches. This change does not alter the functionality of the code.
Signed-off-by: Kuan-Wei Chiu <visitorckw@...il.com>
---
drivers/md/raid5.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 4cb9c608ee19..b14d7ba38f0f 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -1035,11 +1035,7 @@ static int cmp_stripe(void *priv, const struct list_head *a,
struct r5pending_data, sibling);
const struct r5pending_data *db = list_entry(b,
struct r5pending_data, sibling);
- if (da->sector > db->sector)
- return 1;
- if (da->sector < db->sector)
- return -1;
- return 0;
+ return (da->sector > db->sector) - (da->sector < db->sector);
}
static void dispatch_defer_bios(struct r5conf *conf, int target,
--
2.25.1
Powered by blists - more mailing lists