]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: reduce line count
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 17 Jul 2020 02:46:16 +0000 (22:46 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:05:18 +0000 (15:05 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 96407fdb752cf8f182d72d737d64b19a15889f46..43f3497cb28138646d0ba4ef16c1a32dc0d73b65 100644 (file)
@@ -1837,16 +1837,17 @@ static inline bool mast_rebalance_from_cousins(struct maple_subtree_state *mast)
 }
 
 static inline void
-mas_ascend_free(struct ma_state *l_mas, struct ma_state *r_mas,
-               struct ma_topiary *free)
-{
-       struct maple_enode *left = l_mas->node;
-       struct maple_enode *right = r_mas->node;
-       mas_ascend(l_mas);
-       mas_ascend(r_mas);
-       mat_add(free, left);
+mast_ascend_free(struct maple_subtree_state *mast)
+{
+       struct maple_enode *left = mast->orig_l->node;
+       struct maple_enode *right = mast->orig_r->node;
+       mas_ascend(mast->orig_l);
+       mas_ascend(mast->orig_r);
+       mat_add(mast->free, left);
        if (left != right)
-               mat_add(free, right);
+               mat_add(mast->free, right);
+       mas_set_slot(mast->orig_l, 0);
+       mas_set_slot(mast->orig_r, 0);
 }
 
 static inline struct maple_enode
@@ -1964,7 +1965,35 @@ static inline void mas_wmb_replace(struct ma_state *mas,
        if (mt_is_alloc(mas->tree))
                mas_update_gap(mas, false);
 }
+static inline void mast_new_root(struct maple_subtree_state *mast,
+                                struct ma_state *mas)
+{
+       unsigned long range_min, range_max;
 
+       mas_mn(mast->l)->parent =
+               ma_parent_ptr(((unsigned long)mas->tree | MA_ROOT_PARENT));
+       mas->depth = mast->orig_l->depth;
+       mast->bn->b_end = 0;
+       if (mte_is_root(mast->orig_l->node)) {
+               if ((mast->orig_l->node != mas->node) &&
+                   (mast->l->depth > mas->tree->ma_height)) {
+                       mat_add(mast->free, mas->node);
+               }
+       } else {
+               do {
+                       mast_ascend_free(mast);
+                       mas_node_walk(mast->orig_l,
+                                     mte_node_type(mast->orig_l->node),
+                                     &range_min, &range_max);
+                       mas_node_walk(mast->orig_r,
+                                     mte_node_type(mast->orig_r->node),
+                                     &range_min, &range_max);
+                       mast_consume(mast);
+               } while (!mte_is_root(mast->orig_l->node));
+       }
+       mat_add(mast->free, mast->orig_l->node);
+       mas_dup_state(mast->orig_l, mast->l);
+}
 /* Private
  *
  * mas_combine_separate() - Follow the tree upwards from @l_mas and @r_mas for
@@ -1983,7 +2012,7 @@ static inline void mas_wmb_replace(struct ma_state *mas,
  * Returns the number of elements in b_node during the last loop.
  */
 static inline int mas_combine_separate(struct ma_state *mas,
-               struct maple_subtree_state *mast, unsigned char count)
+                                      struct maple_subtree_state *mast, unsigned char count)
 {
        unsigned char split, r_end, mid_split;
        unsigned char slot = 0, l_slot = 0;
@@ -2045,39 +2074,13 @@ static inline int mas_combine_separate(struct ma_state *mas,
                mast->orig_l->depth++;
 
                if (!l_mas.min && l_mas.max == ULONG_MAX) {
-                       mas_mn(&l_mas)->parent = ma_parent_ptr(
-                             ((unsigned long)mas->tree | MA_ROOT_PARENT));
-                       mas->depth = mast->orig_l->depth;
-                       mast->bn->b_end = 0;
-                       if (mte_is_root(mast->orig_l->node)) {
-                               if ((mast->orig_l->node != mas->node) &&
-                                   (l_mas.depth > mas->tree->ma_height)) {
-                                       mat_add(&free, mas->node);
-                               }
-                       } else {
-                               do {
-                                       mas_ascend_free(mast->orig_l, mast->orig_r,
-                                                       &free);
-                                       mas_set_slot(mast->orig_l, 0);
-                                       mas_set_slot(mast->orig_r, 0);
-                                       mas_node_walk(mast->orig_l,
-                                             mte_node_type(mast->orig_l->node),
-                                             &range_min, &range_max);
-                                       mas_node_walk(mast->orig_r,
-                                             mte_node_type(mast->orig_r->node),
-                                             &range_min, &range_max);
-                                       mast_consume(mast);
-                               } while (!mte_is_root(mast->orig_l->node));
-                       }
-                       mat_add(mast->free, mast->orig_l->node);
-                       mas_dup_state(mast->orig_l, &l_mas);
+                       mast_new_root(mast, mas);
                        goto new_root;
                }
 
-               mas_ascend_free(mast->orig_l, mast->orig_r, &free);
+               mast_ascend_free(mast);
                /* Set up the right side of things */
                r_end = mas_data_end(mast->orig_r);
-               mas_set_slot(mast->orig_r, 0);
                mast->orig_r->index = r_mas.max;
                /* last should be larger than or equal to index */
                if (mast->orig_r->last < mast->orig_r->index)
@@ -2091,7 +2094,6 @@ static inline int mas_combine_separate(struct ma_state *mas,
                        mas_set_slot(mast->orig_r, r_end + 1);
                }
                /* Set up the left side of things */
-               mas_set_slot(mast->orig_l, 0);
                mast->orig_l->index = l_mas.min;
                mas_node_walk(mast->orig_l, mte_node_type(mast->orig_l->node),
                              &range_min, &range_max);
@@ -2199,7 +2201,7 @@ static inline int mas_rebalance(struct ma_state *mas,
 }
 
 static inline int mas_split(struct ma_state *mas,
-                                  struct maple_big_node *b_node)
+                           struct maple_big_node *b_node)
 {
 
        struct maple_enode *ancestor = MAS_NONE;