From bb3db4e3030b59e2f5324df5c0a3df5ddfcb1bdc Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Sun, 17 Feb 2019 17:01:21 -0500 Subject: [PATCH] maple_tree: Optimize _mas_walk Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 3f0aeee47063..b2f7cbddf7e1 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1284,16 +1284,18 @@ static inline bool _mas_walk(struct ma_state *mas) enum maple_type type; struct maple_node *next; unsigned long pivot_cnt, pivot, max, min, i; + bool ret = true; mas->node = mas_start(mas); + min = mas->min; + max = mas->max; while (true) { type = mt_node_type(mas->node); pivot_cnt = mt_pivots[type]; - min = mas->min; - max = mas->max; - if (pivot_cnt) { + switch (type) { + default: pivot = 0; for (i = 0; i < pivot_cnt; i++) { pivot = _ma_get_pivot(mas->node, i, type); @@ -1309,30 +1311,34 @@ static inline bool _mas_walk(struct ma_state *mas) min = pivot; } - if (i == pivot_cnt - 1) { - if (mas->index > pivot) + if ((i == pivot_cnt - 1) && (mas->index > pivot)) i++; - } - } else { + + if (type < maple_range_16) // Leaf. + goto done; + break; + + case maple_dense: // Linear node. i = mas->index - mas->min; if (mas->min) i--; + goto done; + break; } - ma_set_slot(mas, i); - if (type < maple_range_16) // Leaf. - return true; - next = _ma_get_rcu_slot(mas->node, i, type); if (!next) // Not found. - return type < maple_range_16; + goto done; // Traverse. mas->max = max; mas->min = min; mas->node = next; } +done: + ma_set_slot(mas, i); + return ret; } static inline void ma_insert(struct ma_state *mas, void *entry) -- 2.50.1