Skip to content

Commit 524f14b

Browse files
fdmananakdave
authored andcommitted
btrfs: remove pointless loop at btrfs_get_next_valid_item()
It's pointless to have a while loop at btrfs_get_next_valid_item(), as if the slot on the current leaf is beyond the last item, we call btrfs_next_leaf(), which leaves us at a valid slot of the next leaf (or a valid slot in the current leaf if after releasing the path an item gets pushed from the next leaf to the current leaf). So just call btrfs_next_leaf() if the current slot on the current leaf is beyond the last item. Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 604e668 commit 524f14b

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

fs/btrfs/ctree.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,26 +2490,15 @@ int btrfs_search_backwards(struct btrfs_root *root, struct btrfs_key *key,
24902490
int btrfs_get_next_valid_item(struct btrfs_root *root, struct btrfs_key *key,
24912491
struct btrfs_path *path)
24922492
{
2493-
while (1) {
2493+
if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
24942494
int ret;
2495-
const int slot = path->slots[0];
2496-
const struct extent_buffer *leaf = path->nodes[0];
24972495

2498-
/* This is where we start walking the path. */
2499-
if (slot >= btrfs_header_nritems(leaf)) {
2500-
/*
2501-
* If we've reached the last slot in this leaf we need
2502-
* to go to the next leaf and reset the path.
2503-
*/
2504-
ret = btrfs_next_leaf(root, path);
2505-
if (ret)
2506-
return ret;
2507-
continue;
2508-
}
2509-
/* Store the found, valid item in @key. */
2510-
btrfs_item_key_to_cpu(leaf, key, slot);
2511-
break;
2496+
ret = btrfs_next_leaf(root, path);
2497+
if (ret)
2498+
return ret;
25122499
}
2500+
2501+
btrfs_item_key_to_cpu(path->nodes[0], key, path->slots[0]);
25132502
return 0;
25142503
}
25152504

0 commit comments

Comments
 (0)