From 06759c0860b6143cde7778f87e65be44dda0592f Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 17 Nov 2026 17:01:51 -0500 Subject: [PATCH] Represent active XML adaptation frame without unwraps --- crates/vectordrawable/src/xml.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/vectordrawable/src/xml.rs b/crates/vectordrawable/src/xml.rs index 40a13761c..fce744f8b 100644 --- a/crates/vectordrawable/src/xml.rs +++ b/crates/vectordrawable/src/xml.rs @@ -70,29 +70,30 @@ fn item(it: Item) -> wire::Item { // Explicit iterator frames keep traversal scratch proportional to depth, not sibling count. fn items(input: Vec) -> Vec { - let mut frames = vec![(input.into_iter(), Vec::new(), None::)]; + let mut parents = Vec::new(); + let mut current = (input.into_iter(), Vec::new()); loop { - let depth = frames.len(); - let frame = frames.last_mut().unwrap(); - if let Some(mut source) = frame.0.next() { + let depth = parents.len() + 1; + if let Some(mut source) = current.0.next() { let children = match &mut source.kind { ItemKind::Group(g) => std::mem::take(&mut g.children), ItemKind::Path(_) => Vec::new(), }; let mapped = item(source); if !children.is_empty() && depth < XML_DEPTH { - frames.push((children.into_iter(), Vec::new(), Some(mapped))); + let previous = std::mem::replace(&mut current, (children.into_iter(), Vec::new())); + parents.push((previous, mapped)); } else { discard_items(children); - frame.1.push(mapped); + current.1.push(mapped); } } else { - let (_, children, parent) = frames.pop().unwrap(); - let Some(mut parent) = parent else { return children }; + let Some((mut previous, mut parent)) = parents.pop() else { return current.1 }; if let wire::ItemKind::Group(g) = &mut parent.kind { - g.children = children; + g.children = current.1; } - frames.last_mut().unwrap().1.push(parent); + previous.1.push(parent); + current = previous; } } }