Skip to content

Commit 10de00c

Browse files
Sun YangKaikdave
authored andcommitted
btrfs: remove unnecessary btrfs_key local variable in btrfs_search_forward()
The 'found_key' variable was only used to temporarily store the found key before copying it to 'min_key' at the end of the function when returning success. Eliminate the 'found_key' variable, and directly store the key into 'min_key' at the exact loop exit points where ret=0 is set, maintaining identical functionality. Signed-off-by: Sun YangKai <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 140ac52 commit 10de00c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

fs/btrfs/ctree.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4607,7 +4607,6 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
46074607
u64 min_trans)
46084608
{
46094609
struct extent_buffer *cur;
4610-
struct btrfs_key found_key;
46114610
int slot;
46124611
int sret;
46134612
u32 nritems;
@@ -4643,7 +4642,8 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
46434642
goto find_next_key;
46444643
ret = 0;
46454644
path->slots[level] = slot;
4646-
btrfs_item_key_to_cpu(cur, &found_key, slot);
4645+
/* Save our key for returning back. */
4646+
btrfs_item_key_to_cpu(cur, min_key, slot);
46474647
goto out;
46484648
}
46494649
if (sret && slot > 0)
@@ -4678,11 +4678,11 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
46784678
goto out;
46794679
}
46804680
}
4681-
/* save our key for returning back */
4682-
btrfs_node_key_to_cpu(cur, &found_key, slot);
46834681
path->slots[level] = slot;
46844682
if (level == path->lowest_level) {
46854683
ret = 0;
4684+
/* Save our key for returning back. */
4685+
btrfs_node_key_to_cpu(cur, min_key, slot);
46864686
goto out;
46874687
}
46884688
cur = btrfs_read_node_slot(cur, slot);
@@ -4699,10 +4699,8 @@ int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
46994699
}
47004700
out:
47014701
path->keep_locks = keep_locks;
4702-
if (ret == 0) {
4702+
if (ret == 0)
47034703
btrfs_unlock_up_safe(path, path->lowest_level + 1);
4704-
memcpy(min_key, &found_key, sizeof(found_key));
4705-
}
47064704
return ret;
47074705
}
47084706

0 commit comments

Comments
 (0)