]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Drop mas_tree_gap & pass more through from _mas_store
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 24 Nov 2020 17:19:31 +0000 (12:19 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 5 Jan 2021 17:31:27 +0000 (12:31 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index ab207b44afed193358979a276cc5b7487c386046..6ed0e70f2326e53ba1daf0e738090412ab9fe419 100644 (file)
@@ -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))