]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: optimize mas_rev_awalk and mas_awalk a bit
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 1 Dec 2020 21:36:30 +0000 (16:36 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 5 Jan 2021 17:33:31 +0000 (12:33 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 19f87c067991cd14961848c456c5b032e7f43758..b50b7cb6092707bad0b243a3ff4a4f51a328d9a4 100644 (file)
@@ -3956,7 +3956,7 @@ static inline bool _mas_awalk(struct ma_state *mas, unsigned long size)
 {
        enum maple_type type = mte_node_type(mas->node);
        unsigned long pivot, min, gap = 0;
-       unsigned char offset = 0;
+       unsigned char count, offset = 0;
        unsigned long *gaps = NULL, *pivots = ma_pivots(mas_mn(mas), type);
        void **slots = ma_slots(mas_mn(mas), type);
        bool found = false;
@@ -3971,8 +3971,9 @@ static inline bool _mas_awalk(struct ma_state *mas, unsigned long size)
                gaps = ma_gaps(mte_to_node(mas->node), type);
        }
 
+       count = mt_slots[type];
        min = mas_safe_min(mas, pivots, offset);
-       for (; offset < mt_slots[type]; offset++) {
+       for (; offset < count; offset++) {
                pivot = _mas_safe_pivot(mas, pivots, offset, type);
                if (offset && !pivot)
                        break;
@@ -4179,27 +4180,35 @@ void mas_rev_awalk(struct ma_state *mas, unsigned long size)
 /* Skip this slot in the parent. */
 static inline bool mas_skip_node(struct ma_state *mas)
 {
-       unsigned char slot;
+       unsigned char slot, slot_count;
+       unsigned long *pivots;
+       enum maple_type mt;
 
+       mt = mte_node_type(mas->node);
+       slot_count = mt_slots[mt] - 1;
        do {
                if (mte_is_root(mas->node)) {
                        slot = mas->offset;
-                       if (slot > mt_slot_count(mas->node) - 1) {
+                       if (slot > slot_count) {
                                mas_set_err(mas, -EBUSY);
                                return false;
                        }
                } else {
                        slot = mte_parent_slot(mas->node);
                        mas_ascend(mas);
+                       mt = mte_node_type(mas->node);
+                       slot_count = mt_slots[mt] - 1;
                }
-       } while (slot > mt_slot_count(mas->node) - 1);
+       } while (slot > slot_count);
 
        mas->offset = ++slot;
+       pivots = ma_pivots(mas_mn(mas), mt);
        if (slot > 0)
-               mas->min = mte_pivot(mas->node, slot - 1) + 1;
+               mas->min = pivots[slot - 1] + 1;
+
+       if (slot <= slot_count)
+               mas->max = pivots[slot];
 
-       if (slot < mt_pivot_count(mas->node))
-               mas->max = mte_pivot(mas->node, slot);
        return true;
 }