expand: leaf nodes out of the recursion frame

This commit is contained in:
Meta Vens 2026-11-28 00:34:58 +01:00
commit 68bf0e1ff0
2 changed files with 39 additions and 24 deletions

View file

@ -326,11 +326,46 @@ impl<'a> Expander<'a> {
}
},
Node::Use(used) => self.expand_use(used, scope, depth, root)?,
Node::Text(_) | Node::Image(_) | Node::Toggle(_) | Node::Slider(_) | Node::TextInput(_) | Node::Select(_) | Node::Plot(_) | Node::Embed(_) => {
self.leaf(node, scope, root)?
}
Node::Box(b) => {
let common = self.common(&b.common, scope, root)?;
let children = self.children(&b.children, scope, depth + 1)?;
Node::Box(BoxNode { common, style: b.style.clone(), paint: b.paint.clone(), role: b.role.clone(), children })
}
Node::Button(b) => {
let common = self.common(&b.common, scope, root)?;
let on_activate = self.command(&b.on_activate, scope)?;
let enabled = self.boolean(&b.enabled, scope)?;
let content = self.children(&b.content, scope, depth + 1)?;
Node::Button(ButtonNode { common, content, on_activate, enabled })
}
Node::Repeat(r) => {
let common = self.common(&r.common, scope, root)?;
let collection = self.collection(&r.collection, scope)?;
let template = std::boxed::Box::new(self.node(&r.template, scope, depth + 1, false)?);
Node::Repeat(RepeatNode { common, collection, key_member: r.key_member.clone(), template })
}
Node::Overlay(o) => {
let common = self.common(&o.common, scope, root)?;
let anchor = match &o.anchor {
Anchor::Viewport => Anchor::Viewport,
Anchor::Node(anchor) => Anchor::Node(AnchorNode { node: self.id(&anchor.node, scope) }),
};
let dismiss = self.command(&o.dismiss, scope)?;
let children = self.children(&o.children, scope, depth + 1)?;
Node::Overlay(OverlayNode { common, anchor, modal: o.modal, dismiss, children })
}
})
}
/// The nodes with no child list. Apart from `node` so that its frame, which every level of the
/// recursion pays for, holds only what a container needs.
#[inline(never)]
fn leaf(&mut self, node: &Node, scope: Option<&Scope>, root: bool) -> Res<Node> {
Ok(match node {
Node::Text(t) => {
let common = self.common(&t.common, scope, root)?;
let content = self.text(&t.content, scope)?;
@ -341,13 +376,6 @@ impl<'a> Expander<'a> {
let alt = self.text(&i.alt, scope)?;
Node::Image(ImageNode { common, alt, ..i.clone() })
}
Node::Button(b) => {
let common = self.common(&b.common, scope, root)?;
let on_activate = self.command(&b.on_activate, scope)?;
let enabled = self.boolean(&b.enabled, scope)?;
let content = self.children(&b.content, scope, depth + 1)?;
Node::Button(ButtonNode { common, content, on_activate, enabled })
}
Node::Toggle(t) => {
let common = self.common(&t.common, scope, root)?;
let checked = self.boolean(&t.checked, scope)?;
@ -381,22 +409,6 @@ impl<'a> Expander<'a> {
let on_change = self.command(&s.on_change, scope)?;
Node::Select(SelectNode { common, options, value, on_change })
}
Node::Repeat(r) => {
let common = self.common(&r.common, scope, root)?;
let collection = self.collection(&r.collection, scope)?;
let template = std::boxed::Box::new(self.node(&r.template, scope, depth + 1, false)?);
Node::Repeat(RepeatNode { common, collection, key_member: r.key_member.clone(), template })
}
Node::Overlay(o) => {
let common = self.common(&o.common, scope, root)?;
let anchor = match &o.anchor {
Anchor::Viewport => Anchor::Viewport,
Anchor::Node(anchor) => Anchor::Node(AnchorNode { node: self.id(&anchor.node, scope) }),
};
let dismiss = self.command(&o.dismiss, scope)?;
let children = self.children(&o.children, scope, depth + 1)?;
Node::Overlay(OverlayNode { common, anchor, modal: o.modal, dismiss, children })
}
Node::Plot(p) => {
let common = self.common(&p.common, scope, root)?;
Node::Plot(PlotNode { common, series: self.bind(&p.series), ..p.clone() })
@ -405,6 +417,9 @@ impl<'a> Expander<'a> {
let common = self.common(&e.common, scope, root)?;
Node::Embed(EmbedNode { common, ..e.clone() })
}
Node::Slot(_) | Node::Use(_) | Node::Box(_) | Node::Button(_) | Node::Repeat(_) | Node::Overlay(_) => {
unreachable!("node() handles containers, Use and Slot")
}
})
}

View file

@ -954,4 +954,4 @@ fn a_slot_naming_a_param_of_another_kind_is_invalid() {
});
}
const STACK_TEST_DEPTH: usize = 900;
const STACK_TEST_DEPTH: usize = 1100;