diff mbox series

btrfs: get next entry in tree_search_offset before doing checks

Message ID 20211122151646.14235-1-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: get next entry in tree_search_offset before doing checks | expand

Commit Message

Nikolay Borisov Nov. 22, 2021, 3:16 p.m. UTC
This is a small optimisation since the currenty 'entry' is already
checked in the if () {} else if {} construct above the loop. In essence
the first iteration of the final while loop is redundant. To eliminate
this extra check simply get the next entry at the beginning of the loop.
---
 fs/btrfs/free-space-cache.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Josef Bacik Nov. 22, 2021, 4:47 p.m. UTC | #1
On Mon, Nov 22, 2021 at 05:16:46PM +0200, Nikolay Borisov wrote:
> This is a small optimisation since the currenty 'entry' is already
> checked in the if () {} else if {} construct above the loop. In essence
> the first iteration of the final while loop is redundant. To eliminate
> this extra check simply get the next entry at the beginning of the loop.

You forgot your signed-off-by, but you can add my

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
David Sterba Nov. 22, 2021, 6:24 p.m. UTC | #2
On Mon, Nov 22, 2021 at 05:16:46PM +0200, Nikolay Borisov wrote:
> This is a small optimisation since the currenty 'entry' is already
> checked in the if () {} else if {} construct above the loop. In essence
> the first iteration of the final while loop is redundant. To eliminate
> this extra check simply get the next entry at the beginning of the loop.
> ---

Added to misc-next, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index f3fee88c8ee0..145a07b19359 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -1686,6 +1686,10 @@  tree_search_offset(struct btrfs_free_space_ctl *ctl,
 		return NULL;
 
 	while (1) {
+		n = rb_next(&entry->offset_index);
+		if (!n)
+			return NULL;
+		entry = rb_entry(n, struct btrfs_free_space, offset_index);
 		if (entry->bitmap) {
 			if (entry->offset + BITS_PER_BITMAP *
 			    ctl->unit > offset)
@@ -1694,11 +1698,6 @@  tree_search_offset(struct btrfs_free_space_ctl *ctl,
 			if (entry->offset + entry->bytes > offset)
 				break;
 		}
-
-		n = rb_next(&entry->offset_index);
-		if (!n)
-			return NULL;
-		entry = rb_entry(n, struct btrfs_free_space, offset_index);
 	}
 	return entry;
 }