From d63a2afd2f82b8dd3d2b0985716c297375f474cd Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 22 Sep 2026 07:34:05 +0000 Subject: [PATCH] Optimize nested find in XML parsing Replaces multiple redundant evaluations of `.find('>')` with a single evaluation, storing the result in a variable and reusing it. This provides a measurable performance improvement for large strings. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- stdlib/src/xml.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/stdlib/src/xml.rs b/stdlib/src/xml.rs index 7ea890c4..d4f04739 100644 --- a/stdlib/src/xml.rs +++ b/stdlib/src/xml.rs @@ -19,12 +19,14 @@ impl StdlibRegistry { callback: |_ctx, args| { let xml = args[0].try_into_string()?; let mut map = IndexMap::new(); - if xml.starts_with('<') && xml.contains('>') { - let tag_name = xml[1..xml.find('>').unwrap_or(1)].to_string(); - let close_tag = format!("", tag_name); - if let Some(close_pos) = xml.find(&close_tag) { - let content = xml[xml.find('>').unwrap() + 1..close_pos].to_string(); - map.insert(tag_name, RuntimeValue::Str(content)); + if xml.starts_with('<') { + if let Some(gt_pos) = xml.find('>') { + let tag_name = xml[1..gt_pos].to_string(); + let close_tag = format!("", tag_name); + if let Some(close_pos) = xml.find(&close_tag) { + let content = xml[gt_pos + 1..close_pos].to_string(); + map.insert(tag_name, RuntimeValue::Str(content)); + } } } Ok(RuntimeValue::Map {