From 408ce5268fc2fbf73f214703c1476aef5f44bcb5 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Tue, 10 Mar 2026 20:40:14 +0000 Subject: [PATCH] Mini perf optimisation --- src/operation_transformation/edited_text.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/operation_transformation/edited_text.rs b/src/operation_transformation/edited_text.rs index 48c854a..93779fb 100644 --- a/src/operation_transformation/edited_text.rs +++ b/src/operation_transformation/edited_text.rs @@ -435,6 +435,7 @@ where ) -> Result, DiffError> { let mut operations: Vec> = Vec::with_capacity(diff.len()); let mut order = 0; + let text_length = original_text.chars().count(); for item in diff { match item { @@ -443,7 +444,6 @@ where let length = usize::try_from(length).expect("length must fit in usize"); // Validate that the range doesn't exceed the original text - let text_length = original_text.chars().count(); if order + length > text_length { return Err(DiffError::LengthExceedsOriginal { position: order, @@ -466,7 +466,6 @@ where usize::try_from(-length).expect("negative length must fit in usize"); // Validate that the delete range doesn't exceed the original text - let text_length = original_text.chars().count(); if order + length > text_length { return Err(DiffError::LengthExceedsOriginal { position: order,