From 56cbf96fe2b3b82d34b2e69a49bcb7b0c0267f6a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 26 Jul 2021 00:08:08 +0200 Subject: Move incremental test into separate function --- src/layout/tree.rs | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'src/layout') diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 258f1ccc..77b01ad2 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -50,6 +50,15 @@ pub struct LayoutNode { } impl LayoutNode { + /// Create a new instance from any node that satisifies the required bounds. + #[cfg(not(feature = "layout-cache"))] + pub fn new(node: T) -> Self + where + T: Layout + Debug + Clone + Eq + PartialEq + 'static, + { + Self { node: Box::new(node) } + } + /// Create a new instance from any node that satisifies the required bounds. #[cfg(feature = "layout-cache")] pub fn new(node: T) -> Self @@ -65,15 +74,6 @@ impl LayoutNode { Self { node: Box::new(node), hash } } - - /// Create a new instance from any node that satisifies the required bounds. - #[cfg(not(feature = "layout-cache"))] - pub fn new(node: T) -> Self - where - T: Layout + Debug + Clone + Eq + PartialEq + 'static, - { - Self { node: Box::new(node) } - } } impl Layout for LayoutNode { @@ -82,20 +82,17 @@ impl Layout for LayoutNode { ctx: &mut LayoutContext, regions: &Regions, ) -> Vec>> { + #[cfg(not(feature = "layout-cache"))] + return self.node.layout(ctx, regions); + #[cfg(feature = "layout-cache")] - { + ctx.layouts.get(self.hash, regions.clone()).unwrap_or_else(|| { ctx.level += 1; - let frames = ctx.layouts.get(self.hash, regions.clone()).unwrap_or_else(|| { - let frames = self.node.layout(ctx, regions); - ctx.layouts.insert(self.hash, frames.clone(), ctx.level - 1); - frames - }); + let frames = self.node.layout(ctx, regions); ctx.level -= 1; + ctx.layouts.insert(self.hash, frames.clone(), ctx.level); frames - } - - #[cfg(not(feature = "layout-cache"))] - self.node.layout(ctx, regions) + }) } } -- cgit v1.2.3