]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
abstract data calc from mas_wr_spanning_rebalance()
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 21 Aug 2025 20:21:57 +0000 (16:21 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 21 Aug 2025 20:21:57 +0000 (16:21 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/maple_tree.c

index d24b8fb12636d825a8514f09f0ee1d96e7661e3d..a83d5a5b01d9bcdeb63a1c618359da0ba728a433 100644 (file)
@@ -2957,6 +2957,48 @@ static void mt_dump_node(const struct maple_tree *mt, void *entry,
                unsigned long min, unsigned long max, unsigned int depth,
                enum mt_dump_format format);
 
+static inline void spanning_data_calc(struct maple_copy *cp,
+               struct ma_state *mas, struct maple_subtree_state *mast,
+               struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas,
+               struct ma_state *sib)
+{
+       /* data from left + new entry */
+       cp->data = mast->orig_l->offset + 1;
+       printk("data size is off %u + 1\n", mast->orig_l->offset);
+       printk("write is now %lx - %lx => %p\n", mas->index, mas->last, l_wr_mas->entry);
+       /* new entry will overwrite one part of left */
+       if (l_wr_mas->r_min == mas->index) {
+               printk("min doesn't split, subtrack one\n");
+               cp->data--;
+       } else {
+               printk("min splits start %lx vs %lx\n", l_wr_mas->r_min, mas->index);
+       }
+
+       printk("%p data + 1 = %u\n", mast->orig_l->node, cp->data);
+
+       /* Data from right (offset to end) + 1 for zero, +1 for splitting */
+       cp->data += mast->orig_r->end - mast->orig_r->offset + 2;
+       printk("end %u - off %u + 1\n", mast->orig_r->end, mast->orig_r->offset);
+       /* new entry splits the insert location */
+       printk("end piv %lx vs last %lx\n", r_wr_mas->r_max, mas->last);
+       if (r_wr_mas->r_max == mas->last) {
+               printk("cp->data--\n");
+               cp->data--;
+       }
+
+       printk("%p data = %u\n", mast->orig_r->node, cp->data);
+
+       if (((mast->orig_l->min != 0) || (mast->orig_r->max != ULONG_MAX)) &&
+           (cp->data < mt_min_slots[l_wr_mas->type])) {
+               mas_spanning_move(mast, sib);
+               cp->data += sib->end + 1;
+               printk("%p data = %u\n", sib->node, cp->data);
+       } else {
+               sib->end = 0;
+       }
+
+}
+
 static void spanning_data_write(struct maple_copy *cp, struct ma_state *mas)
 {
        struct maple_node *dst, *src;
@@ -3267,42 +3309,9 @@ static noinline void mas_wr_spanning_rebalance(struct ma_state *mas,
         */
 
        mt_dump(mas->tree, mt_dump_hex);
-       /* data from left + new entry */
-       cp.data = mast->orig_l->offset + 1;
-       printk("data size is off %u + 1\n", mast->orig_l->offset);
-       printk("write is now %lx - %lx => %p\n", mas->index, mas->last, l_wr_mas->entry);
-       /* new entry will overwrite one part of left */
-       if (l_wr_mas->r_min == mas->index) {
-               printk("min doesn't split, subtrack one\n");
-               cp.data--;
-       } else {
-               printk("min splits start %lx vs %lx\n", l_wr_mas->r_min, mas->index);
-       }
-
-       printk("%p data + 1 = %u\n", mast->orig_l->node, cp.data);
-
-       /* Data from right (offset to end) + 1 for zero, +1 for splitting */
-       cp.data += mast->orig_r->end - mast->orig_r->offset + 2;
-       printk("end %u - off %u + 1\n", mast->orig_r->end, mast->orig_r->offset);
-       /* new entry splits the insert location */
-       printk("end piv %lx vs last %lx\n", r_wr_mas->r_max, mas->last);
-       if (r_wr_mas->r_max == mas->last) {
-               printk("cp.data--\n");
-               cp.data--;
-       }
-
-       printk("%p data = %u\n", mast->orig_r->node, cp.data);
 
+       spanning_data_calc(&cp, mas, mast, l_wr_mas, r_wr_mas, &sib);
        mt = l_wr_mas->type;
-       if (((mast->orig_l->min != 0) || (mast->orig_r->max != ULONG_MAX)) &&
-           (cp.data < mt_min_slots[mt])) {
-               mas_spanning_move(mast, &sib);
-               cp.data += sib.end + 1;
-               printk("%p data = %u\n", sib.node, cp.data);
-       } else {
-               sib.end = 0;
-       }
-
        cp.d_count = 0;
        /* Calc split here */
        if (cp.data < mt_slots[mt]) {