]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: mas_data_end reduction #2
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 4 Sep 2020 20:23:23 +0000 (16:23 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:11:11 +0000 (15:11 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 153b5dfd6e9110d53b5c17ae7b7f0b92b7fd133a..74354f7f0e8cc3ab8debc6978b1e8fd7a7bb8e7d 100644 (file)
@@ -1633,8 +1633,9 @@ static inline struct maple_enode *mte_node_or_none(struct maple_enode *enode)
  */
 static inline void mast_topiary(struct maple_subtree_state *mast)
 {
-       unsigned char l_slot, r_slot, slot, end;
+       unsigned char l_slot, r_slot, slot;
        unsigned long l_index,  range_min, range_max;
+       struct maple_enode *child;
 
        // The left node is consumed, so add to the free list.
        l_index = mast->orig_l->index;
@@ -1655,9 +1656,13 @@ static inline void mast_topiary(struct maple_subtree_state *mast)
                return;
 
        /* Now destroy l_slot + 1 -> end and 0 -> r_slot - 1 */
-       end = mas_data_end(mast->orig_l);
-       for (slot = l_slot + 1; slot <= end; slot++)
-               mat_add(mast->destroy, mas_get_slot(mast->orig_l, slot));
+       slot = l_slot + 1;
+       while (slot < mt_slot_count(mast->orig_l->node)) {
+               child = mas_get_slot(mast->orig_l, slot++);
+               if (!child)
+                       break;
+               mat_add(mast->destroy, child);
+       }
 
        for (slot = 0; slot < r_slot; slot++)
                mat_add(mast->destroy, mas_get_slot(mast->orig_r, slot));
@@ -2759,7 +2764,6 @@ static inline bool mas_wr_walk(struct ma_state *mas, unsigned long *range_min,
                type = mte_node_type(mas->node);
                mas->depth++;
 
-               end = mas_data_end(mas);
                if (unlikely(!mas_node_walk(mas, type, range_min, range_max)))
                        return false;
 
@@ -2769,6 +2773,7 @@ static inline bool mas_wr_walk(struct ma_state *mas, unsigned long *range_min,
                if (ma_is_leaf(type))
                        return true;
 
+               end = mas_data_end(mas);
                if (end <= mt_min_slots[type])
                        mas_cnt_empty(mas);
                else if (end >= mt_slots[type] - 2)