From: Liam R. Howlett Date: Tue, 24 Nov 2020 17:19:31 +0000 (-0500) Subject: maple_tree: Drop mas_tree_gap & pass more through from _mas_store X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=36b8d944d10edab6d000db1b26bb7cd8ddeca70c;p=users%2Fjedix%2Flinux-maple.git maple_tree: Drop mas_tree_gap & pass more through from _mas_store Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index ab207b44afed..6ed0e70f2326 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1085,7 +1085,7 @@ static inline unsigned long mas_leaf_max_gap(struct ma_state *mas) unsigned char i; unsigned char max_piv; - if (ma_is_dense(mt)) { + if (unlikely(ma_is_dense(mt))) { for (i = 0; i < mt_slots[mt]; i++) { if (slots[i]) { if (gap > max_gap) @@ -1163,22 +1163,7 @@ static inline unsigned long mas_max_gap(struct ma_state *mas) return gaps[offset]; } -static inline unsigned long mas_tree_gap(struct ma_state *mas) -{ - struct maple_node *pnode; - unsigned long *gaps; - enum maple_type mt; - if (!mte_is_root(mas->node)) { - - pnode = mte_parent(mas->node); - mt = mas_parent_enum(mas, mas->node); - gaps = ma_gaps(pnode, mt); - return gaps[mte_parent_slot(mas->node)]; - - } - return mas_max_gap(mas); -} static inline void mas_parent_gap(struct ma_state *mas, unsigned char offset, unsigned long new) { @@ -2928,7 +2913,7 @@ bool mas_is_span_wr(struct ma_state *mas, unsigned long piv, if (piv > mas->last) // Contained in this pivot return false; - if (ma_is_leaf(type)) { + if (unlikely(ma_is_leaf(type))) { if (mas->last < mas->max) // Fits in the node, but may span slots. return false; @@ -3184,12 +3169,12 @@ static inline int mas_spanning_store(struct ma_state *mas, void *entry) static inline bool mas_node_store(struct ma_state *mas, void *entry, unsigned long min, unsigned long max, - unsigned char end, void *content) + unsigned char end, void *content, + enum maple_type mt, void **slots, + unsigned long *pivots) { - enum maple_type mt = mte_node_type(mas->node); - struct maple_node *node = mas_mn(mas); - void **dst_slots, **slots = ma_slots(node, mt); - unsigned long *dst_pivots, *pivots = ma_pivots(node, mt); + void **dst_slots; + unsigned long *dst_pivots; unsigned char dst_offset, new_end = end; unsigned char offset, offset_end; struct maple_node reuse, *newnode; @@ -3289,11 +3274,10 @@ done: static inline bool mas_slot_store(struct ma_state *mas, void *entry, unsigned long min, unsigned long max, - unsigned char end, void *content) + unsigned char end, void *content, + enum maple_type mt, void **slots) { - enum maple_type mt = mte_node_type(mas->node); struct maple_node *node = mas_mn(mas); - void **slots = ma_slots(node, mt); unsigned long *pivots = ma_pivots(node, mt); unsigned long lmax; // Logical max. unsigned char offset = mas->offset; @@ -3341,7 +3325,7 @@ done: return true; try_node_store: - return mas_node_store(mas, entry, min, max, end, content); + return mas_node_store(mas, entry, min, max, end, content, mt, slots, pivots); } static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite) @@ -3350,6 +3334,8 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite unsigned char end; void *content = NULL; struct maple_big_node b_node; + void **slots; + enum maple_type mt; int ret = 0; @@ -3376,16 +3362,15 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite /* At this point, we are at the leaf node that needs to be altered. */ /* Calculate needed space */ - content = mas_get_slot(mas, mas->offset); + mt = mte_node_type(mas->node); + slots = ma_slots(mas_mn(mas), mt); + content = slots[mas->offset]; if (!overwrite && ((mas->last > r_max) || content)) { mas_set_err(mas, -EEXIST); return content; } if (!entry) { - enum maple_type mt = mte_node_type(mas->node); - unsigned long *pivots = ma_pivots(mas_mn(mas), mt); - void **slots = ma_slots(mas_mn(mas), mt); unsigned char offset_end = mas->offset; if (!content) { @@ -3395,6 +3380,7 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite mas->last = r_max; // if this one is null the next and prev are not. } else { + unsigned long *pivots = ma_pivots(mas_mn(mas), mt); // Check next slot if we are overwriting the end. if ((mas->last == r_max) && !slots[mas->offset + 1]) { if (mas->offset < mt_pivots[mt] - 1 && @@ -3426,7 +3412,7 @@ static inline void *_mas_store(struct ma_state *mas, void *entry, bool overwrite } end = mas_data_end(mas); - if (mas_slot_store(mas, entry, r_min, r_max, end, content)) + if (mas_slot_store(mas, entry, r_min, r_max, end, content, mt, slots)) return content; if (mas_is_err(mas))