mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
btrfs: use rb_find_add() in insert_ref_entry()
Use the rb-tree helper so we don't open code the search and insert code. Signed-off-by: Yangtao Li <frank.li@vivo.com> 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:
+11
-20
@@ -162,30 +162,21 @@ static int comp_refs(struct ref_entry *ref1, struct ref_entry *ref2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ref_entry_cmp(struct rb_node *new, const struct rb_node *existing)
|
||||
{
|
||||
struct ref_entry *new_entry = rb_entry(new, struct ref_entry, node);
|
||||
struct ref_entry *existing_entry = rb_entry(existing, struct ref_entry, node);
|
||||
|
||||
return comp_refs(new_entry, existing_entry);
|
||||
}
|
||||
|
||||
static struct ref_entry *insert_ref_entry(struct rb_root *root,
|
||||
struct ref_entry *ref)
|
||||
{
|
||||
struct rb_node **p = &root->rb_node;
|
||||
struct rb_node *parent_node = NULL;
|
||||
struct ref_entry *entry;
|
||||
int cmp;
|
||||
|
||||
while (*p) {
|
||||
parent_node = *p;
|
||||
entry = rb_entry(parent_node, struct ref_entry, node);
|
||||
cmp = comp_refs(entry, ref);
|
||||
if (cmp > 0)
|
||||
p = &(*p)->rb_left;
|
||||
else if (cmp < 0)
|
||||
p = &(*p)->rb_right;
|
||||
else
|
||||
return entry;
|
||||
}
|
||||
|
||||
rb_link_node(&ref->node, parent_node, p);
|
||||
rb_insert_color(&ref->node, root);
|
||||
return NULL;
|
||||
struct rb_node *node;
|
||||
|
||||
node = rb_find_add(&ref->node, root, ref_entry_cmp);
|
||||
return rb_entry_safe(node, struct ref_entry, node);
|
||||
}
|
||||
|
||||
static struct root_entry *lookup_root_entry(struct rb_root *root, u64 objectid)
|
||||
|
||||
Reference in New Issue
Block a user