]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: mas_node_walk() and mas_node_store()
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 12 Oct 2021 14:49:20 +0000 (10:49 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 20 Oct 2021 19:23:10 +0000 (15:23 -0400)
node_walk: Just set *ranges in leaf case, otherwise set mas->max/min
node_store: Just reverse order of if/else

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c

index 0e65002fa26c616c7f357ca86ad4b2c66f6f9efb..cc11db1104fd5fa2cd388e2e9c6947f74f469e19 100644 (file)
@@ -3669,7 +3669,6 @@ static inline void mas_node_walk(struct ma_state *mas, struct maple_node *node,
        unsigned char offset;
        unsigned long index;
 
-       pivots = ma_pivots(node, type);
        if (unlikely(ma_is_dense(type))) {
                (*range_max) = (*range_min) = mas->index;
                if (unlikely(ma_dead_node(node)))
@@ -3681,6 +3680,7 @@ static inline void mas_node_walk(struct ma_state *mas, struct maple_node *node,
 
        offset = 0;
        min = mas->min;
+       pivots = ma_pivots(node, type);
        max = pivots[offset];
        if (unlikely(ma_dead_node(node)))
                return;
@@ -3709,9 +3709,14 @@ static inline void mas_node_walk(struct ma_state *mas, struct maple_node *node,
 
        max = mas->max;
 done:
-       *range_max = max;
-       *range_min = min;
        mas->offset = offset;
+       if (ma_is_leaf(type)) {
+               *range_max = max;
+               *range_min = min;
+       } else {
+               mas->max = max;
+               mas->min = min;
+       }
 }
 /*
  * __mas_walk(): Locates a value and sets the mas->node and slot accordingly.
@@ -3746,9 +3751,6 @@ static inline bool __mas_walk(struct ma_state *mas, unsigned long *range_min,
 
                /* Descend. */
                mas->node = next;
-               mas->max = *range_max;
-               mas->min = *range_min;
-               mas->offset = 0;
        }
        return false;
 }
@@ -4001,11 +4003,11 @@ done:
                ma_set_meta(newnode, maple_leaf_64, 0, new_end);
        }
 
-       if (!mt_in_rcu(mas->tree)) {
-               memcpy(mas_mn(mas), newnode, sizeof(struct maple_node));
-       } else {
+       if (likely(mt_in_rcu(mas->tree))) {
                mas->node = mt_mk_node(newnode, mt);
                mas_replace(mas, false);
+       } else {
+               memcpy(mas_mn(mas), newnode, sizeof(struct maple_node));
        }
        trace_ma_write(__func__, mas, 0, entry);
        mas_update_gap(mas);