]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: mas_first_entry() optimization
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 7 Dec 2020 00:53:05 +0000 (19:53 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 5 Jan 2021 17:33:33 +0000 (12:33 -0500)
Remove loop in favour of checking pivot 0 or 1 as one mus have a value.

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

index 8d8e16f8eb366f37cff44baa9acab394030685da..f3cc0b571789d743f6df6c24482718f2376ba757 100644 (file)
@@ -1275,9 +1275,12 @@ static inline void mas_update_gap(struct ma_state *mas)
 static inline unsigned long mas_first_entry(struct ma_state *mas,
                unsigned long limit)
 {
-       void **slots, *entry;
        unsigned long max = mas->max, range_start = mas->min;
        unsigned char offset;
+       unsigned long *pivots;
+       struct maple_node *mn;
+       void **slots;
+       enum maple_type mt;
 
        while (likely(!mte_is_leaf(mas->node))) {
                max = mte_pivot(mas->node, 0);
@@ -1285,18 +1288,29 @@ static inline unsigned long mas_first_entry(struct ma_state *mas,
        }
 
        mas->max = max;
-       slots = ma_slots(mte_to_node(mas->node), mte_node_type(mas->node));
+       mn = mas_mn(mas);
+       mt = mte_node_type(mas->node);
+       slots = ma_slots(mn, mt);
 
+       /* 0 or 1 must be set */
        offset = 0;
-       while ((range_start < limit) &&
-              (offset < mt_slot_count(mas->node))) {
-               entry = mas_slot(mas, slots, offset);
-               if (entry)
-                       goto done;
-               range_start = mas_safe_pivot(mas, offset) + 1;
-               offset++;
-       }
+       range_start = mas->min;
+       if (range_start > limit)
+               goto none;
+
+       if(likely(mas_slot(mas, slots, offset)))
+               goto done;
+
+       pivots = ma_pivots(mn, mt);
+       range_start = pivots[0] + 1;
+
+       if (range_start > limit)
+               goto none;
+
+       if(likely(mas_slot(mas, slots, ++offset)))
+               goto done;
 
+none:
        mas->node = MAS_NONE;
 done:
        mas->offset = offset;