]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Rework mas_destroy_rebalance()
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 9 Dec 2020 22:01:03 +0000 (17:01 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 5 Jan 2021 17:33:37 +0000 (12:33 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index ee01dc762fcdf37f1ce70104420bcbcb6ae4332d..515c0ac41517398b998e3d4b9ef5a617fb1b6e82 100644 (file)
@@ -2502,7 +2502,7 @@ static inline void mas_destroy_rebalance(struct ma_state *mas,
                                         unsigned char mas_end)
 {
        enum maple_type mt = mte_node_type(mas->node);
-       struct maple_node reuse, *newnode, *parent, *new_left;
+       struct maple_node reuse, *newnode, *parent, *new_left, *left, *node;
        struct maple_enode *eparent;
        unsigned char offset, tmp, split = mt_slots[mt] / 2;
        void **l_slots, **slots;
@@ -2521,19 +2521,20 @@ static inline void mas_destroy_rebalance(struct ma_state *mas,
 
                newnode = mas_pop_node(mas);
        } else {
-               memset(&reuse, 0, sizeof(struct maple_node));
                newnode = &reuse;
        }
 
-       newnode->parent = mas_mn(mas)->parent;
+       node = mas_mn(mas);
+       newnode->parent = node->parent;
        pivs = ma_pivots(newnode, mt);
 
 
 
        slots = ma_slots(newnode, mt);
        pivs = ma_pivots(newnode, mt);
-       l_slots = ma_slots(mas_mn(&l_mas), mt);
-       l_pivs = ma_pivots(mas_mn(&l_mas), mt);
+       left = mas_mn(&l_mas);
+       l_slots = ma_slots(left, mt);
+       l_pivs = ma_pivots(left, mt);
        if (!l_slots[split])
                split++;
        tmp = mas_data_end(&l_mas) - split;
@@ -2541,16 +2542,23 @@ static inline void mas_destroy_rebalance(struct ma_state *mas,
        memcpy(slots, l_slots + split + 1, sizeof(void *) * tmp);
        memcpy(pivs, l_pivs + split + 1, sizeof(unsigned long) * tmp);
        pivs[tmp] = l_mas.max;
-       memcpy(slots + tmp, ma_slots(mas_mn(mas), mt), sizeof(void *) * mas_end);
-       memcpy(pivs + tmp, ma_pivots(mas_mn(mas), mt), sizeof(unsigned long) * mas_end);
+       memcpy(slots + tmp, ma_slots(node, mt), sizeof(void *) * mas_end);
+       memcpy(pivs + tmp, ma_pivots(node, mt), sizeof(unsigned long) * mas_end);
 
        l_mas.max = l_pivs[split];
        mas->min = l_mas.max + 1;
        eparent = mt_mk_node(mte_parent(l_mas.node),
                             mas_parent_enum(&l_mas, l_mas.node));
        if (!mt_in_rcu(mas->tree)) {
-
-               memcpy(mas_mn(mas), newnode, sizeof(struct maple_node));
+               tmp += mas_end - 1;
+               if (tmp < mt_pivots[mt])
+                       memset(pivs + tmp, 0,
+                             sizeof (unsigned long *) * (mt_pivots[mt] - tmp));
+               if (tmp < mt_slots[mt])
+                       memset(slots + tmp, 0,
+                             sizeof (void *) * (mt_pivots[mt] - tmp));
+
+               memcpy(node, newnode, sizeof(struct maple_node));
                mte_set_pivot(eparent, mte_parent_slot(l_mas.node),
                              l_pivs[split]);
                // Remove data from l_pivs.
@@ -2569,7 +2577,7 @@ static inline void mas_destroy_rebalance(struct ma_state *mas,
 
        // replace l_mas
        new_left = mas_pop_node(mas);
-       new_left->parent = mas_mn(&l_mas)->parent;
+       new_left->parent = left->parent;
        mt = mte_node_type(l_mas.node);
        slots = ma_slots(new_left, mt);
        pivs = ma_pivots(new_left, mt);