Message ID | 20211123072342.21371-1-nborisov@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] btrfs: eliminate if in main loop in tree_search_offset | expand |
On Tue, Nov 23, 2021 at 09:23:42AM +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. > > Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Thanks, Josef
On Tue, Nov 23, 2021 at 09:23:42AM +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. > > Signed-off-by: Nikolay Borisov <nborisov@suse.com> > --- > V2: > * Set entry to NULL by default so that semantics is unchanged. Added to misc-next, thanks.
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 145a07b19359..c5ee980e7a5e 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -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) {
Reshuffle the code inside the first loop of tree_search_offset so that one if() is eliminated and the becomes more linear. Signed-off-by: Nikolay Borisov <nborisov@suse.com> --- 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(-)