diff mbox

[3/7] Btrfs: ref_node_cmp decrease max compare count

Message ID 20170607005844.2078-4-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 8 comparison,
just add some new checks to switch check branch faster
now in worst case code do 5 comparison

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

Patch

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 24865da63..2e4709e0c 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -120,25 +120,29 @@  static void ref_root_free(struct ref_root *ref_tree)
  */
 static int ref_node_cmp(struct ref_node *a, struct ref_node *b)
 {
-	if (a->root_id < b->root_id)
-		return -1;
-	else if (a->root_id > b->root_id)
+	if (a->root_id != b->root_id) {
+		if (a->root_id < b->root_id)
+			return -1;
 		return 1;
+	}
 
-	if (a->object_id < b->object_id)
-		return -1;
-	else if (a->object_id > b->object_id)
+	if (a->object_id != b->object_id) {
+		if (a->object_id < b->object_id)
+			return -1;
 		return 1;
+	}
 
-	if (a->offset < b->offset)
-		return -1;
-	else if (a->offset > b->offset)
+	if (a->offset != b->offset) {
+		if (a->offset < b->offset)
+			return -1;
 		return 1;
+	}
 
-	if (a->parent < b->parent)
-		return -1;
-	else if (a->parent > b->parent)
+	if (a->parent != b->parent) {
+		if (a->parent < b->parent)
+			return -1;
 		return 1;
+	}
 
 	return 0;
 }