From: Liam R. Howlett Date: Tue, 6 Jul 2021 19:01:12 +0000 (-0400) Subject: maple_tree: Drop mas_dup_state() and copy the entire struct X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d326c9595970b566726ded7dc542221000616a65;p=users%2Fjedix%2Flinux-maple.git maple_tree: Drop mas_dup_state() and copy the entire struct Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index d870344c2538..feeb4639bb75 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -915,23 +915,6 @@ static void mas_mat_free(struct ma_state *mas, struct ma_topiary *mat, } } -/* - * mas_dup_state() - duplicate the internal state of a ma_state. - * @dst - the destination to store the state information - * @src - the source of the state information - */ -static inline void mas_dup_state(struct ma_state *dst, struct ma_state *src) -{ - dst->tree = src->tree; - dst->index = src->index; - dst->last = src->last; - dst->node = src->node; - dst->max = src->max; - dst->min = src->min; - dst->offset = src->offset; - dst->mas_flags = src->mas_flags; -} - /* * mas_descend() - Descend into the slot stored in the ma_state. * @mas - the maple state. @@ -1637,7 +1620,7 @@ static inline bool mas_new_child(struct ma_state *mas, struct ma_state *child) break; if (mte_parent(entry) == node) { - mas_dup_state(child, mas); + *child = *mas; mas->offset = offset + 1; child->offset = offset; mas_descend(child); @@ -1887,11 +1870,11 @@ static inline void mas_descend_adopt(struct ma_state *mas) int i, n; for (i = 0; i < 3; i++) { - mas_dup_state(&list[i], mas); + list[i] = *mas; list[i].offset = 0; next[i].offset = 0; } - mas_dup_state(&next[0], mas); + next[0] = *mas; while (!mte_is_leaf(list[0].node)) { @@ -1914,7 +1897,7 @@ static inline void mas_descend_adopt(struct ma_state *mas) /* descend by setting the list to the children */ for (i = 0; i < 3; i++) - mas_dup_state(&list[i], &next[i]); + list[i] = next[i]; } } @@ -2057,7 +2040,7 @@ static inline bool mas_next_sibling(struct ma_state *mas) if (mte_is_root(mas->node)) return false; - mas_dup_state(&parent, mas); + parent = *mas; mas_ascend(&parent); end = mas_data_end(&parent); parent.offset = mte_parent_slot(mas->node) + 1; @@ -2067,7 +2050,7 @@ static inline bool mas_next_sibling(struct ma_state *mas) if (!mas_get_slot(&parent, parent.offset)) return false; - mas_dup_state(mas, &parent); + *mas = parent; mas_descend(mas); return true; } @@ -2223,20 +2206,20 @@ bool mast_cousin_rebalance_right(struct maple_subtree_state *mast, bool free) MA_STATE(tmp, mast->orig_r->tree, mast->orig_r->index, mast->orig_r->last); - mas_dup_state(&tmp, mast->orig_r); + tmp = *mast->orig_r; mas_next_node(mast->orig_r, ULONG_MAX); if (!mas_is_none(mast->orig_r)) { mast_rebalance_next(mast, old_r, free); return true; } - mas_dup_state(mast->orig_r, mast->orig_l); - mas_dup_state(mast->r, mast->l); + *mast->orig_r = *mast->orig_l; + *mast->r = *mast->l; mas_prev_node(mast->orig_l, 0); if (mas_is_none(mast->orig_l)) { /* Making a new root with the contents of mast->bn */ - mas_dup_state(mast->orig_l, mast->orig_r); - mas_dup_state(mast->orig_r, &tmp); + *mast->orig_l = *mast->orig_r; + *mast->orig_r = tmp; return false; } @@ -2757,12 +2740,14 @@ new_root: if (!mte_dead_node(mast->orig_l->node)) mat_add(&free, mast->orig_l->node); - mas_dup_state(mast->orig_l, &l_mas); mas->depth = mast->orig_l->depth; + *mast->orig_l = l_mas; mte_set_node_dead(mas->node); /* Set up mas for insertion. */ - mas_dup_state(mas, mast->orig_l); + mast->orig_l->depth = mas->depth; + mast->orig_l->alloc = mas->alloc; + *mas = *mast->orig_l; mas_wmb_replace(mas, &free, &destroy); mas->offset = restore.offset; mas->min = restore.min; @@ -2802,8 +2787,7 @@ static inline int mas_rebalance(struct ma_state *mas, mast.orig_r = &r_mas; mast.bn = b_node; - mas_dup_state(&l_mas, mas); - mas_dup_state(&r_mas, mas); + l_mas = r_mas = *mas; if (mas_next_sibling(&r_mas)) { mas_mab_cp(&r_mas, 0, mt_slot_count(r_mas.node), b_node, b_end); @@ -2842,7 +2826,7 @@ static inline void mas_destroy_rebalance(struct ma_state *mas, unsigned char end MA_STATE(l_mas, mas->tree, mas->index, mas->last); - mas_dup_state(&l_mas, mas); + l_mas = *mas; mas_prev_sibling(&l_mas); /* set up node. */ @@ -3101,8 +3085,8 @@ static inline bool mas_push_data(struct ma_state *mas, int height, unsigned char end, space, split; MA_STATE(tmp_mas, mas->tree, mas->index, mas->last); + tmp_mas = *mas; tmp_mas.depth = mast->l->depth; - tmp_mas.node = mas->node; if (left && !mas_prev_sibling(&tmp_mas)) return false; @@ -3139,14 +3123,14 @@ static inline bool mas_push_data(struct ma_state *mas, int height, if (left) { /* Switch mas to prev node */ mat_add(mast->free, mas->node); - mas_dup_state(mas, &tmp_mas); + *mas = tmp_mas; /* Start using mast->l for the left side. */ tmp_mas.node = mast->l->node; - mas_dup_state(mast->l, &tmp_mas); + *mast->l = tmp_mas; } else { mat_add(mast->free, tmp_mas.node); tmp_mas.node = mast->r->node; - mas_dup_state(mast->r, &tmp_mas); + *mast->r = tmp_mas; split = slot_total - split; } split = mab_no_null_split(mast->bn, split, mt_slots[mast->bn->type]); @@ -3200,8 +3184,7 @@ static int mas_split(struct ma_state *mas, struct maple_big_node *b_node) if (mas_split_final_node(&mast, mas, height)) break; - mas_dup_state(&l_mas, mas); - mas_dup_state(&r_mas, mas); + l_mas = r_mas = *mas; l_mas.node = mas_new_ma_node(mas, b_node); r_mas.node = mas_new_ma_node(mas, b_node); /* Try to push left. */ @@ -3220,8 +3203,8 @@ static int mas_split(struct ma_state *mas, struct maple_big_node *b_node) */ mast.r->max = mas->max; mast_fill_bnode(&mast, mas, 1); - mas_dup_state(&prev_l_mas, mast.l); - mas_dup_state(&prev_r_mas, mast.r); + prev_l_mas = *mast.l; + prev_r_mas = *mast.r; } /* Set the original node as dead */ @@ -3707,7 +3690,7 @@ static inline int mas_spanning_store(struct ma_state *mas, void *entry) mast.orig_r = &r_mas; /* Set up right side. */ - mas_dup_state(&r_mas, mas); + r_mas = *mas; r_mas.depth = mas->depth; /* Avoid overflow. */ if (r_mas.last + 1) @@ -3719,7 +3702,7 @@ static inline int mas_spanning_store(struct ma_state *mas, void *entry) r_mas.last = r_mas.index = mas->last; /* Set up left side. */ - mas_dup_state(&l_mas, mas); + l_mas = *mas; l_mas.depth = mas->depth; l_mas.offset = 0; __mas_walk(&l_mas, &range_min, &range_max);