From 03cfb01942b77f77bf46fed9f780c07e9e6484e6 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Mon, 23 Oct 2023 18:54:04 +0200 Subject: [PATCH] Simplify one of the cases in transaction composition. --- sub_crates/backend/src/transaction.rs | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/sub_crates/backend/src/transaction.rs b/sub_crates/backend/src/transaction.rs index 8a5e3a2..a5066ec 100644 --- a/sub_crates/backend/src/transaction.rs +++ b/sub_crates/backend/src/transaction.rs @@ -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);