diff mbox series

btrfs: eliminate if in main loop in tree_search_offset

Message ID 20211122151713.14316-1-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: eliminate if in main loop in tree_search_offset | expand

Commit Message

Nikolay Borisov Nov. 22, 2021, 3:17 p.m. UTC
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(-)

Comments

Josef Bacik Nov. 22, 2021, 4:50 p.m. UTC | #1
On Mon, Nov 22, 2021 at 05:17:13PM +0200, Nikolay Borisov wrote:
> 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
Nikolay Borisov Nov. 23, 2021, 6:50 a.m. UTC | #2
On 22.11.21 г. 18:50, Josef Bacik wrote:
> On Mon, Nov 22, 2021 at 05:17:13PM +0200, Nikolay Borisov wrote:
>> 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....

> 
> Josef
>
diff mbox series

Patch

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 145a07b19359..141fae2692a4 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -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) {