Skip to contentSkip to conversation

btrfs: eliminate if in main loop in tree_search_offset

PATCH In review Nikolay Borisov 3 participants 3 messages Nov 23, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs: eliminate if in main loop in tree_search_offset

Reshuffle the code inside the first loop of tree_search_offset so that one if() is eliminated and the becomes more linear.

---
V2:
* Set entry to NULL by default so that semantics is unchanged.

 fs/btrfs/free-space-cache.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
fs/btrfs/free-space-cache.c +4 -7
index 145a07b19359..c5ee980e7a5e 100644
@@ -1592,15 +1592,10 @@ tree_search_offset(struct btrfs_free_space_ctl *ctl,
 		   u64 offset, int bitmap_only, int fuzzy)
 {
 	struct rb_node *n = ctl->free_space_offset.rb_node;
-	struct btrfs_free_space *entry, *prev = NULL;
+	struct btrfs_free_space *entry = NULL, *prev = NULL;
 
 	/* find entry that is closest to the 'offset' */
-	while (1) {
-		if (!n) {
-			entry = NULL;
-			break;
-		}
-
+	while (n) {
 		entry = rb_entry(n, struct btrfs_free_space, offset_index);
 		prev = entry;
 
@@ -1610,6 +1605,8 @@ tree_search_offset(struct btrfs_free_space_ctl *ctl,
 			n = n->rb_right;
 		else
 			break;
+
+		entry = NULL;
 	}
 
 	if (bitmap_only) {
Signature · 1 line
2.17.1