From: Liam R. Howlett Date: Thu, 10 Apr 2025 18:13:16 +0000 (-0400) Subject: converged converted X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9b38fa423cba71eb68c96382095635dc9faed2ef;p=users%2Fjedix%2Flinux-maple.git converged converted Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 59a536d09f89..f6418ec2a2a6 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3784,61 +3784,60 @@ void mns_assemble(struct ma_node_state *states, unsigned char len) } } +struct split_data { + /* + * Used to split the data between two nodes. + * The user of this struct, mt_wr_split_data(), must keep track of the + * offset into the entire data (up to two nodes worth), so that the + * insert can be placed in the correct place while the source data that + * is overwritten is skipped. + */ + unsigned char offset; /* Offset into destination data (entire set) */ + unsigned char space; /* The space left in the current destination node */ + unsigned char split; /* Proposed split of data */ + unsigned char insert; /* Insert location of destination */ + unsigned char new_end; /* Total data */ + unsigned char src_ins_end; + struct ma_node_state *state; + struct ma_node_state states[5]; + int len; +}; + static inline void mas_wr_converged(struct ma_node_info *src, struct ma_node_info *dst, struct ma_node_part *ma_part, - struct ma_state *mas) - + struct ma_state *mas, struct split_data *sd) { - struct ma_node_state converged[3]; - unsigned char i = 0; unsigned char off = 0; + sd->len = 0; mni_node_init(dst, mas_pop_node(mas), src->type); if (src->insert_off) { - mns_mni_init(&converged[i], dst, 0, src->insert_off); - converged[i].info = src; + mns_mni_init(&sd->states[sd->len], dst, 0, src->insert_off); + sd->states[sd->len].info = src; + sd->len++; off = src->insert_off; - i++; } - mns_mni_init(&converged[i], dst, 0, ma_part->size); - converged[i].part = ma_part; - converged[i].use_part = true; + mns_mni_init(&sd->states[sd->len], dst, 0, ma_part->size); + sd->states[sd->len].part = ma_part; + sd->states[sd->len].use_part = true; + sd->len++; off += ma_part->skip; - i++; if (src->end >= off) { unsigned char start = off; unsigned char size = src->end - start + 1; - mns_mni_init(&converged[i], dst, start, size); - converged[i].info = src; - i++; + mns_mni_init(&sd->states[sd->len], dst, start, size); + sd->states[sd->len].info = src; + sd->len++; off += size - 1; } - mns_assemble(converged, i); + mns_assemble(sd->states, sd->len); dst->node->parent = src->node->parent; mni_finalise(dst); } -struct split_data { - /* - * Used to split the data between two nodes. - * The user of this struct, mt_wr_split_data(), must keep track of the - * offset into the entire data (up to two nodes worth), so that the - * insert can be placed in the correct place while the source data that - * is overwritten is skipped. - */ - unsigned char offset; /* Offset into destination data (entire set) */ - unsigned char space; /* The space left in the current destination node */ - unsigned char split; /* Proposed split of data */ - unsigned char insert; /* Insert location of destination */ - unsigned char new_end; /* Total data */ - unsigned char src_ins_end; - struct ma_node_state *state; - int i; -}; - /* * * @src: The node information of the source @@ -3866,7 +3865,7 @@ static int mt_wr_split_data(struct ma_node_info *src, struct ma_node_info *to; state = sd->state; - i = sd->i; + i = sd->len; /* Offset into the destination data where the insert ends */ insert_end = sd->insert + ma_part->size - 1; @@ -4023,7 +4022,7 @@ try_right: state[i].info = &src2; mns_mni_init(&state[i], left, 0, src2.end + 1); i++; - sd->i++; + sd->len++; } /* @@ -4046,7 +4045,7 @@ try_right: mas->end = parent.end; mas->offset = parent.insert_off; ma_part->skip = 2; - mas_wr_converged(&parent, &new_parent, ma_part, mas); + mas_wr_converged(&parent, &new_parent, ma_part, mas, sd); src->enode = parent.enode; mas->node = new_parent.enode; return true; @@ -4256,7 +4255,7 @@ static void mas_wr_split(struct ma_wr_state *wr_mas) mns_node_part_leaf_init(&part, wr_mas, &src); sd.new_end = mas->end + part.size; /* - skip + 1 */ sd.src_ins_end = wr_mas->offset_end; - sd.i = 0; + sd.len = 0; if (height > 1 && mas_wr_try_rebalance(mas, &src, &left, &right, &part, &sd)) goto rebalanced; @@ -4290,7 +4289,7 @@ static void mas_wr_split(struct ma_wr_state *wr_mas) mni_node_init(&left, mas_pop_node(mas), src.type); mni_node_init(&right, mas_pop_node(mas), src.type); sd.src_ins_end = src.insert_off; - sd.i = 0; + sd.len = 0; if ((height > 1) && (mas_wr_try_rebalance(mas, &src, &left, &right, &part, &sd))) goto rebalanced; @@ -4328,7 +4327,7 @@ new_root: * set the skip to high enough to avoid using any data */ converged: - mas_wr_converged(&src, &parent, &part, mas); + mas_wr_converged(&src, &parent, &part, mas, &sd); mas->node = parent.enode; rebalanced: mas_wmb_replace(mas, src.enode);