diff --git a/benches/oneshot.rs b/benches/oneshot.rs index 57e3b339d..6ce81a639 100644 --- a/benches/oneshot.rs +++ b/benches/oneshot.rs @@ -60,7 +60,7 @@ fn bench_eval(iai: &mut Iai) { fn bench_to_tree(iai: &mut Iai) { let (mut ctx, id) = context(); let module = ctx.evaluate(id).unwrap(); - iai.run(|| module.template.to_tree(ctx.style())); + iai.run(|| module.template.to_pages(ctx.style())); } fn bench_layout(iai: &mut Iai) { diff --git a/src/eval/array.rs b/src/eval/array.rs index 17192cb34..f6adee6d8 100644 --- a/src/eval/array.rs +++ b/src/eval/array.rs @@ -7,6 +7,7 @@ use std::rc::Rc; use super::Value; use crate::diag::StrResult; +use crate::util::RcExt; /// Create a new [`Array`] from values. #[allow(unused_macros)] @@ -169,10 +170,7 @@ impl IntoIterator for Array { type IntoIter = std::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { - match Rc::try_unwrap(self.0) { - Ok(vec) => vec.into_iter(), - Err(rc) => (*rc).clone().into_iter(), - } + Rc::take(self.0).into_iter() } } diff --git a/src/eval/dict.rs b/src/eval/dict.rs index c0ddf3289..e7a46b400 100644 --- a/src/eval/dict.rs +++ b/src/eval/dict.rs @@ -6,6 +6,7 @@ use std::rc::Rc; use super::{Str, Value}; use crate::diag::StrResult; +use crate::util::RcExt; /// Create a new [`Dict`] from key-value pairs. #[allow(unused_macros)] @@ -135,10 +136,7 @@ impl IntoIterator for Dict { type IntoIter = std::collections::btree_map::IntoIter; fn into_iter(self) -> Self::IntoIter { - match Rc::try_unwrap(self.0) { - Ok(map) => map.into_iter(), - Err(rc) => (*rc).clone().into_iter(), - } + Rc::take(self.0).into_iter() } } diff --git a/src/eval/template.rs b/src/eval/template.rs index 639163394..11ea3f56c 100644 --- a/src/eval/template.rs +++ b/src/eval/template.rs @@ -6,9 +6,9 @@ use std::rc::Rc; use super::Str; use crate::diag::StrResult; -use crate::geom::{Align, Dir, GenAxis, Length, Linear, Sides, Size, SpecAxis}; +use crate::geom::{Align, Dir, GenAxis, Length, Linear, Sides, Size}; use crate::layout::{ - Decoration, LayoutNode, LayoutTree, PadNode, PageRun, ParChild, ParNode, StackChild, + BlockNode, Decoration, InlineNode, PadNode, PageNode, ParChild, ParNode, StackChild, StackNode, }; use crate::style::Style; @@ -34,9 +34,9 @@ enum TemplateNode { /// Spacing. Spacing(GenAxis, Linear), /// An inline node builder. - Inline(Rc LayoutNode>, Vec), + Inline(Rc InlineNode>, Vec), /// An block node builder. - Block(Rc LayoutNode>), + Block(Rc BlockNode>), /// Save the current style. Save, /// Restore the last saved style. @@ -55,7 +55,7 @@ impl Template { pub fn from_inline(f: F) -> Self where F: Fn(&Style) -> T + 'static, - T: Into, + T: Into, { let node = TemplateNode::Inline(Rc::new(move |s| f(s).into()), vec![]); Self(Rc::new(vec![node])) @@ -65,7 +65,7 @@ impl Template { pub fn from_block(f: F) -> Self where F: Fn(&Style) -> T + 'static, - T: Into, + T: Into, { let node = TemplateNode::Block(Rc::new(move |s| f(s).into())); Self(Rc::new(vec![node])) @@ -164,10 +164,10 @@ impl Template { /// Build the layout tree resulting from instantiating the template with the /// given style. - pub fn to_tree(&self, style: &Style) -> LayoutTree { + pub fn to_pages(&self, style: &Style) -> Vec { let mut builder = Builder::new(style, true); builder.template(self); - builder.build_tree() + builder.build_pages() } /// Repeat this template `n` times. @@ -243,8 +243,8 @@ struct Builder { style: Style, /// Snapshots of the style. snapshots: Vec