Simplify one of the cases in transaction composition.

This commit is contained in:
Nathan Vegdahl 2023-10-23 18:54:04 +02:00
parent f8ba027c38
commit 03cfb01942

View File

@ -160,26 +160,27 @@ impl Transaction {
//-----------------
// Replace, Retain
(Some(Replace { .. }), Some(Retain(bc2))) => {
let op1 = next_op1.unwrap();
(
Some(
op1 @ Replace {
old: old1,
new: new1,
},
),
Some(Retain(bc2)),
) => {
if op1.len_post() < bc2 {
trans.push_op(op1, &self.buffer);
next_op1 = ops1.next();
next_op2 = Some(Retain(bc2 - op1.len_post()));
} else if op1.len_post() > bc2 {
let (op1a, op1b) = match op1 {
Op::Retain(bc1) => (Op::Retain(bc2), Op::Retain(bc1 - bc2)),
Op::Replace { old, new } => (
Op::Replace {
old: old,
new: (new.0, new.0 + bc2),
},
Op::Replace {
old: (0, 0),
new: (new.0 + bc2, new.1),
},
),
let op1a = Op::Replace {
old: old1,
new: (new1.0, new1.0 + bc2),
};
let op1b = Op::Replace {
old: (0, 0),
new: (new1.0 + bc2, new1.1),
};
trans.push_op(op1a, &self.buffer);
next_op1 = Some(op1b);