From: Liam R. Howlett Date: Wed, 16 Apr 2025 15:54:58 +0000 (-0400) Subject: code cleanup of try_rebalance X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4088a9ab8d5d800752a9d7fb591bc0ce5e49f14d;p=users%2Fjedix%2Flinux-maple.git code cleanup of try_rebalance Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 158b6a676787..14666ff92a4a 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3965,6 +3965,7 @@ bool can_rebalance_right(struct ma_state *tmp_mas, struct ma_node_info *parent, tmp_mas->offset--; return false; } + return true; } @@ -4019,33 +4020,28 @@ bool mas_wr_try_rebalance(struct ma_state *mas, struct ma_node_info *src, src->end = mas->end; if (can_rebalance_left(&tmp_mas, &parent, &src2, sd)) { + /* Left will be src2, right will be src */ left->min = src2.min; right->max = src->max; + /* Shift split data variables */ + sd->insert = mas->offset + src2.end + 1; + sd->offset = src2.end + 1; + sd->space = sd->split - src2.end; + sd->states[sd->len].info = &src2; + /* The first state to copy is the left node */ + mns_mni_init(&sd->states[sd->len], left, 0, src2.end + 1); + sd->len++; } else if (can_rebalance_right(&tmp_mas, &parent, &src2, sd)) { sd->split = src2.end + sd->new_end - sd->split; left_store = true; /* Left will be src, right will be src2 */ left->min = src->min; right->max = src2.max; - } else { - return false; - } - - /* The rebalance operation will succeed. */ - sd->new_end += src2.end + 1; - if (left_store) { - /* Left pushes data right. */ sd->insert = mas->offset; sd->space = sd->split; sd->offset = 0; } else { - /* Right pushes data left */ - sd->insert = mas->offset + src2.end + 1; - sd->offset = src2.end + 1; - sd->space = sd->split - src2.end; - sd->states[sd->len].info = &src2; - mns_mni_init(&sd->states[sd->len], left, 0, src2.end + 1); - sd->len++; + return false; } /* @@ -4053,8 +4049,10 @@ bool mas_wr_try_rebalance(struct ma_state *mas, struct ma_node_info *src, * There can also be a split between nodes that may happen at these * boundaries, or elsewhere. */ + sd->new_end += src2.end + 1; mt_wr_split_data(src, left, right, part, sd); if (left_store) { + /* Stored to the left, copy the last of the right in src2 */ sd->states[sd->len].info = &src2; mns_mni_init(&sd->states[sd->len], right, 0, src2.end + 1); sd->len++;