diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-31 09:13:31 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-31 10:13:34 +0200 |
| commit | 97858e5992a52459dd8a34be7a6b4786952b491a (patch) | |
| tree | ee4cde4e9cf051a1ecd7d27f13ec26df3ff8df9d /src/model/layout.rs | |
| parent | ccb4753e24eefb5b8cf2acd6d25f0e2afce1c022 (diff) | |
Basic manual tracking
Diffstat (limited to 'src/model/layout.rs')
| -rw-r--r-- | src/model/layout.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/model/layout.rs b/src/model/layout.rs index 92d73977..b0247258 100644 --- a/src/model/layout.rs +++ b/src/model/layout.rs @@ -5,7 +5,7 @@ use std::fmt::{self, Debug, Formatter, Write}; use std::hash::Hash; use std::sync::Arc; -use super::{Barrier, NodeId, Resolve, StyleChain, StyleEntry}; +use super::{Barrier, NodeId, PinConstraint, Resolve, StyleChain, StyleEntry}; use crate::diag::TypResult; use crate::eval::{RawAlign, RawLength}; use crate::frame::{Element, Frame}; @@ -132,6 +132,8 @@ impl Regions { } } +impl_track_hash!(Regions); + /// A type-erased layouting node with a precomputed hash. #[derive(Clone, Hash)] pub struct LayoutNode(Arc<Prehashed<dyn Bounds>>); @@ -221,19 +223,32 @@ impl Layout for LayoutNode { regions: &Regions, styles: StyleChain, ) -> TypResult<Vec<Arc<Frame>>> { - let (result, at, pins) = crate::memo::memoized( + let prev = ctx.pins.dirty.replace(false); + + let (result, at, fresh, dirty) = crate::memo::memoized( (self, &mut *ctx, regions, styles), |(node, ctx, regions, styles)| { + let hash = fxhash::hash64(&ctx.pins); let at = ctx.pins.cursor(); + let entry = StyleEntry::Barrier(Barrier::new(node.id())); let result = node.0.layout(ctx, regions, entry.chain(&styles)); - (result, at, ctx.pins.from(at)) + + let fresh = ctx.pins.from(at); + let dirty = ctx.pins.dirty.get(); + let constraint = PinConstraint(dirty.then(|| hash)); + ((result, at, fresh, dirty), ((), constraint, (), ())) }, ); + ctx.pins.dirty.replace(prev || dirty); + // Replay the side effect in case of caching. This should currently be // more or less the only relevant side effect on the context. - ctx.pins.replay(at, pins); + if dirty { + ctx.pins.replay(at, fresh); + } + result } @@ -242,6 +257,8 @@ impl Layout for LayoutNode { } } +impl_track_hash!(LayoutNode); + impl Default for LayoutNode { fn default() -> Self { EmptyNode.pack() |
