From 43b0a88f4d3eb3d41a46d997582110b62d75a411 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 8 Sep 2020 12:28:24 -0400 Subject: [PATCH] maple_tree: Remove recursive call for ma_get_node_alloc_cnt, and rename function Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 335e48e45a44..ffd99a0f6cae 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -386,7 +386,7 @@ static inline struct maple_node *mas_get_alloc(const struct ma_state *mas) } /* - * ma_get_node_alloc_cnt() - Get the number of allocations stored in this node. + * ma_node_alloc_cnt() - Get the number of allocations stored in this node. * @node: The maple node * * Used to calculate the total allocated nodes in a maple state. See @@ -395,24 +395,16 @@ static inline struct maple_node *mas_get_alloc(const struct ma_state *mas) * Returns: The count of the allocated nodes stored in this nodes slots. * */ -static inline int ma_get_node_alloc_cnt(const struct maple_node *node) +static inline int ma_node_alloc_cnt(const struct maple_node *node) { - int ret = 1; int slot = 0; while (slot < MAPLE_NODE_SLOTS) { if (!node->slot[slot]) - return ret; - - if (ma_mnode_ptr(node->slot[slot])->slot[0]) { - ret += ma_get_node_alloc_cnt( - ma_mnode_ptr(node->slot[slot])); - } else { - ret++; - } + break; slot++; } - return ret; + return slot; } /* @@ -427,11 +419,19 @@ static inline int ma_get_node_alloc_cnt(const struct maple_node *node) static inline int mas_alloc_cnt(const struct ma_state *mas) { struct maple_node *node = mas_get_alloc(mas); + int ret = 1; + int slot = 0; if (!node) return 0; - return ma_get_node_alloc_cnt(node); + slot = ma_node_alloc_cnt(node); + ret += slot; + while (--slot >= 0) { + if (ma_mnode_ptr(node->slot[slot])->slot[0]) + ret += ma_node_alloc_cnt(node->slot[slot]); + } + return ret; } /* -- 2.50.1