[PATCH 1/7] Btrfs: __compare_inode_defrag decrease max compare count

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In worst case code do 4 comparison,
just add some new checks to switch check branch faster
now in worst case code do 3 comparison

Signed-off-by: Timofey Titovets <nefelim4ag@xxxxxxxxx>
---
 fs/btrfs/file.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index da1096eb1..39efda26c 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -71,16 +71,17 @@ struct inode_defrag {
 static int __compare_inode_defrag(struct inode_defrag *defrag1,
 				  struct inode_defrag *defrag2)
 {
-	if (defrag1->root > defrag2->root)
-		return 1;
-	else if (defrag1->root < defrag2->root)
+	if (defrag1->root != defrag2->root) {
+		if (defrag1->root > defrag2->root)
+			return 1;
 		return -1;
-	else if (defrag1->ino > defrag2->ino)
-		return 1;
-	else if (defrag1->ino < defrag2->ino)
+	}
+	if (defrag1->ino != defrag2->ino) {
+		if (defrag1->ino > defrag2->ino)
+			return 1;
 		return -1;
-	else
-		return 0;
+	}
+	return 0;
 }
 
 /* pop a record for an inode into the defrag tree.  The lock
-- 
2.13.0

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux