mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 10:04:04 +02:00
btrfs: use rb_find_add() in rb_simple_insert()
Use the rb-tree helper so we don't open code the search and insert code. Signed-off-by: Pan Chuang <panchuang@vivo.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
c52ea14d05
commit
46d549928c
|
|
@ -119,28 +119,23 @@ static inline struct rb_node *rb_simple_search_first(const struct rb_root *root,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int rb_simple_node_bytenr_cmp(struct rb_node *new, const struct rb_node *existing)
|
||||
{
|
||||
struct rb_simple_node *new_entry = rb_entry(new, struct rb_simple_node, rb_node);
|
||||
struct rb_simple_node *existing_entry = rb_entry(existing, struct rb_simple_node, rb_node);
|
||||
|
||||
if (new_entry->bytenr < existing_entry->bytenr)
|
||||
return -1;
|
||||
else if (new_entry->bytenr > existing_entry->bytenr)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline struct rb_node *rb_simple_insert(struct rb_root *root,
|
||||
struct rb_simple_node *simple_node)
|
||||
{
|
||||
struct rb_node **p = &root->rb_node;
|
||||
struct rb_node *parent = NULL;
|
||||
struct rb_simple_node *entry;
|
||||
|
||||
while (*p) {
|
||||
parent = *p;
|
||||
entry = rb_entry(parent, struct rb_simple_node, rb_node);
|
||||
|
||||
if (simple_node->bytenr < entry->bytenr)
|
||||
p = &(*p)->rb_left;
|
||||
else if (simple_node->bytenr > entry->bytenr)
|
||||
p = &(*p)->rb_right;
|
||||
else
|
||||
return parent;
|
||||
}
|
||||
|
||||
rb_link_node(&simple_node->rb_node, parent, p);
|
||||
rb_insert_color(&simple_node->rb_node, root);
|
||||
return NULL;
|
||||
return rb_find_add(&simple_node->rb_node, root, rb_simple_node_bytenr_cmp);
|
||||
}
|
||||
|
||||
static inline bool bitmap_test_range_all_set(const unsigned long *addr,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user