mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-09 19:51:25 -04:00
btrfs: simplify last record detection at test_range_bit()
The overflow detection for the start offset of the next record is not
really necessary, we can just stop iterating if the current record ends at
or after out end offset. This removes the need to test if the current
record end offset is (u64)-1 and to check if adding 1 to the current
end offset results in 0.
By testing only if the current record ends at or after the end offset, we
also don't need anymore to test the new start offset at the head of the
while loop.
This makes both the source code and assembly code simpler, more efficient
and shorter (reducing the object text size).
Also remove the pointless initialization to NULL of the state variable, as
we don't use it before the first assignment to it. This may help avoid
some warnings with clang tools such as the one reported/fixed by commit
966de47ff0 ("btrfs: remove redundant initialization of variables in
log_new_ancestors").
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
committed by
David Sterba
parent
c54c245f80
commit
53828c759a
@@ -1790,7 +1790,7 @@ void get_range_bits(struct extent_io_tree *tree, u64 start, u64 end, u32 *bits,
|
||||
bool test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bit,
|
||||
struct extent_state *cached)
|
||||
{
|
||||
struct extent_state *state = NULL;
|
||||
struct extent_state *state;
|
||||
bool bitset = true;
|
||||
|
||||
ASSERT(is_power_of_2(bit));
|
||||
@@ -1801,7 +1801,7 @@ bool test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bit,
|
||||
state = cached;
|
||||
else
|
||||
state = tree_search(tree, start);
|
||||
while (state && start <= end) {
|
||||
while (state) {
|
||||
if (state->start > start) {
|
||||
bitset = false;
|
||||
break;
|
||||
@@ -1815,16 +1815,11 @@ bool test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, u32 bit,
|
||||
break;
|
||||
}
|
||||
|
||||
if (state->end == (u64)-1)
|
||||
if (state->end >= end)
|
||||
break;
|
||||
|
||||
/*
|
||||
* Last entry (if state->end is (u64)-1 and overflow happens),
|
||||
* or next entry starts after the range.
|
||||
*/
|
||||
/* Next state must start where this one ends. */
|
||||
start = state->end + 1;
|
||||
if (start > end || start == 0)
|
||||
break;
|
||||
state = next_state(state);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user