Skip to contentSkip to conversation

btrfs: eliminate if in main loop in tree_search_offset

PATCH Superseded Nikolay Borisov 2 participants 3 messages Nov 22, 2021 – Nov 23, 2021 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 fs/btrfs/free-space-cache.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
fs/btrfs/free-space-cache.c +3 -6
index 145a07b19359..141fae2692a4 100644
@@ -1595,12 +1595,7 @@ tree_search_offset(struct btrfs_free_space_ctl *ctl,
 	struct btrfs_free_space *entry, *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
#1 lore raw
Quoted 2 lines · Nikolay Borisov

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

Need a SOB and you need to set entry = NULL initially if you're going to make this change. Thanks,

Josef

#2 lore raw
Quoted 6 lines · Josef Bacik
Quoted 2 lines · Nikolay Borisov

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

Need a SOB and you need to set entry = NULL initially if you're going to make this change. Thanks,

Doh, I had it set before nuking the work via git checkout and on the 2nd try I forgot....

Quoted 3 lines

Josef