From 79638d4bbdc140a8dca0ccfdf70ffd607d5da251 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 16 Nov 2021 12:47:14 +0100 Subject: Don't wrap already layoutable nodes into flows/pars unnecessarily --- src/eval/template.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/eval/template.rs') diff --git a/src/eval/template.rs b/src/eval/template.rs index 82a069f9..0604cc05 100644 --- a/src/eval/template.rs +++ b/src/eval/template.rs @@ -149,12 +149,15 @@ impl Template { Self(Rc::new(vec![TemplateNode::Decorated(deco, self)])) } - /// Build the flow node resulting from instantiating the template with the - /// given style. - pub fn to_flow(&self, style: &Style) -> FlowNode { - let mut builder = Builder::new(style, false); - builder.template(self); - builder.build_flow() + /// Pack the template into a layout node. + pub fn pack(&self, style: &Style) -> PackedNode { + if let [TemplateNode::Block(f) | TemplateNode::Inline(f)] = self.0.as_slice() { + f(style) + } else { + let mut builder = Builder::new(style, false); + builder.template(self); + builder.build_flow().pack() + } } /// Build the layout tree resulting from instantiating the template with the -- cgit v1.2.3