]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Remove recursive call for ma_get_node_alloc_cnt, and rename function
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 8 Sep 2020 16:28:24 +0000 (12:28 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:11:17 +0000 (15:11 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 335e48e45a440492bc8aae073b63afaa9c2ac947..ffd99a0f6cae3a9bf37bd81ba6da45d9300cd923 100644 (file)
@@ -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;
 }
 
 /*