From 5bd0509f90eeeade08988f2017aa0203e5d0330f Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Wed, 24 Sep 2025 22:52:54 -0400 Subject: [PATCH] multi_src_setup(): Add wr_mas optimisation for appending Use already available data, when possible Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 4c8fe5d3889f..1bf4e7524daf 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2338,7 +2338,7 @@ void node_finalise(struct maple_node *node, enum maple_type mt, unsigned char en ma_set_meta(node, mt, gap_slot, end - 1); } -static inline void append_node_cp(struct maple_copy *cp, +static inline void append_mas_cp(struct maple_copy *cp, struct ma_state *mas, unsigned char start, unsigned char end) { struct maple_node *node; @@ -2348,7 +2348,6 @@ static inline void append_node_cp(struct maple_copy *cp, count = cp->s_count; node = mas_mn(mas); mt = mte_node_type(mas->node); - cp->src[count].node = node; cp->src[count].mt = mt; if (mas->end <= end) @@ -2361,6 +2360,24 @@ static inline void append_node_cp(struct maple_copy *cp, cp->s_count++; } +static inline void append_wr_mas_cp(struct maple_copy *cp, + struct ma_wr_state *wr_mas, unsigned char start, unsigned char end) +{ + unsigned char count; + + count = cp->s_count; + cp->src[count].node = wr_mas->node; + cp->src[count].mt = wr_mas->type; + if (wr_mas->mas->end <= end) + cp->src[count].max = wr_mas->mas->max; + else + cp->src[count].max = wr_mas->pivots[end]; + + cp->src[count].start = start; + cp->src[count].end = end; + cp->s_count++; +} + static inline void cp_leaf_init(struct maple_copy *cp, struct ma_state *mas, struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas) @@ -2651,13 +2668,13 @@ void multi_src_setup(struct maple_copy *cp, struct ma_wr_state *l_wr_mas, { cp->s_count = 0; if (sib->end && sib->max < l_wr_mas->mas->min) - append_node_cp(cp, sib, 0, sib->end); + append_mas_cp(cp, sib, 0, sib->end); /* Copy left 0 - offset */ if (l_wr_mas->mas->offset) { unsigned char off = l_wr_mas->mas->offset - 1; - append_node_cp(cp, l_wr_mas->mas, 0, off); + append_wr_mas_cp(cp, l_wr_mas, 0, off); cp->src[cp->s_count - 1].max = cp->min - 1; } @@ -2665,11 +2682,11 @@ void multi_src_setup(struct maple_copy *cp, struct ma_wr_state *l_wr_mas, /* Copy right either from offset or offset + 1 pending on r_max */ if (r_wr_mas->mas->end != r_wr_mas->offset_end) - append_node_cp(cp, r_wr_mas->mas, r_wr_mas->offset_end + 1, + append_wr_mas_cp(cp, r_wr_mas, r_wr_mas->offset_end + 1, r_wr_mas->mas->end); if (sib->end && sib->min > r_wr_mas->mas->max) - append_node_cp(cp, sib, 0, sib->end); + append_mas_cp(cp, sib, 0, sib->end); } static inline -- 2.51.0