diff mbox

[2/7] Btrfs: backref_comp decrease max compare count

Message ID 20170607005844.2078-3-nefelim4ag@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Timofey Titovets June 7, 2017, 12:58 a.m. UTC
In worst case code do 6 comparison,
just add some new checks to switch check branch faster
now in worst case code do 4 comparison

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
---
 fs/btrfs/inode.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
diff mbox

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 17cbe9306..fa024642a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2249,20 +2249,23 @@  struct new_sa_defrag_extent {
 static int backref_comp(struct sa_defrag_extent_backref *b1,
 			struct sa_defrag_extent_backref *b2)
 {
-	if (b1->root_id < b2->root_id)
-		return -1;
-	else if (b1->root_id > b2->root_id)
+	if (b1->root_id != b2->root_id) {
+		if (b1->root_id < b2->root_id)
+			return -1;
 		return 1;
+	}
 
-	if (b1->inum < b2->inum)
-		return -1;
-	else if (b1->inum > b2->inum)
+	if (b1->inum != b2->inum) {
+		if (b1->inum < b2->inum)
+			return -1;
 		return 1;
+	}
 
-	if (b1->file_pos < b2->file_pos)
-		return -1;
-	else if (b1->file_pos > b2->file_pos)
+	if (b1->file_pos != b2->file_pos) {
+		if (b1->file_pos < b2->file_pos)
+			return -1;
 		return 1;
+	}
 
 	/*
 	 * [------------------------------] ===> (a range of space)