From 04faec084e83e9c0d46cf6331d4764a3cdca7027 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 1 Dec 2020 16:36:30 -0500 Subject: [PATCH] maple_tree: optimize mas_rev_awalk and mas_awalk a bit Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 19f87c067991..b50b7cb60927 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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; } -- 2.50.1