Skip to content

Commit ff7b43b

Browse files
authored
Merge pull request #188 from Tcode-Motion/optimize-xml-parsing-10252665756925486722
⚡ Optimize nested find in XML parsing
2 parents 05a09dd + d63a2af commit ff7b43b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎stdlib/src/xml.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ impl StdlibRegistry {
1919
callback: |_ctx, args| {
2020
let xml = args[0].try_into_string()?;
2121
let mut map = IndexMap::new();
22-
if xml.starts_with('<') && xml.contains('>') {
23-
let tag_name = xml[1..xml.find('>').unwrap_or(1)].to_string();
24-
let close_tag = format!("</{}>", tag_name);
25-
if let Some(close_pos) = xml.find(&close_tag) {
26-
let content = xml[xml.find('>').unwrap() + 1..close_pos].to_string();
27-
map.insert(tag_name, RuntimeValue::Str(content));
22+
if xml.starts_with('<') {
23+
if let Some(gt_pos) = xml.find('>') {
24+
let tag_name = xml[1..gt_pos].to_string();
25+
let close_tag = format!("</{}>", tag_name);
26+
if let Some(close_pos) = xml.find(&close_tag) {
27+
let content = xml[gt_pos + 1..close_pos].to_string();
28+
map.insert(tag_name, RuntimeValue::Str(content));
29+
}
2830
}
2931
}
3032
Ok(RuntimeValue::Map {

0 commit comments

Comments
 (0)