summaryrefslogtreecommitdiff
path: root/src/library/structure
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-09-21 17:50:58 +0200
committerLaurenz <laurmaedje@gmail.com>2022-09-21 20:25:57 +0200
commitddd3b6a82b8c0353c942bfba8b89ca5476eedc58 (patch)
treea64c350f0f1f82152ff18cfb02fbfdbf39292672 /src/library/structure
parent3760748fddd3b793c79c370398a9d4a3fc5afc04 (diff)
Tracked memoization
Diffstat (limited to 'src/library/structure')
-rw-r--r--src/library/structure/doc.rs2
-rw-r--r--src/library/structure/heading.rs10
-rw-r--r--src/library/structure/list.rs10
-rw-r--r--src/library/structure/reference.rs2
-rw-r--r--src/library/structure/table.rs15
5 files changed, 28 insertions, 11 deletions
diff --git a/src/library/structure/doc.rs b/src/library/structure/doc.rs
index ba848b64..c3af3f1c 100644
--- a/src/library/structure/doc.rs
+++ b/src/library/structure/doc.rs
@@ -9,7 +9,7 @@ impl DocNode {
/// Layout the document into a sequence of frames, one per page.
pub fn layout(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
styles: StyleChain,
) -> SourceResult<Vec<Frame>> {
let mut frames = vec![];
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index 855c0503..01738496 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -82,13 +82,13 @@ impl Show for HeadingNode {
}
}
- fn realize(&self, _: &dyn World, _: StyleChain) -> SourceResult<Content> {
+ fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> {
Ok(Content::block(self.body.clone()))
}
fn finalize(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
styles: StyleChain,
mut realized: Content,
) -> SourceResult<Content> {
@@ -149,7 +149,11 @@ pub enum Leveled<T> {
impl<T: Cast + Clone> Leveled<T> {
/// Resolve the value based on the level.
- pub fn resolve(&self, world: &dyn World, level: NonZeroUsize) -> SourceResult<T> {
+ pub fn resolve(
+ &self,
+ world: Tracked<dyn World>,
+ level: NonZeroUsize,
+ ) -> SourceResult<T> {
Ok(match self {
Self::Value(value) => value.clone(),
Self::Mapping(mapping) => mapping(level),
diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs
index f63374f3..9da14733 100644
--- a/src/library/structure/list.rs
+++ b/src/library/structure/list.rs
@@ -100,7 +100,11 @@ impl<const L: ListKind> Show for ListNode<L> {
}
}
- fn realize(&self, world: &dyn World, styles: StyleChain) -> SourceResult<Content> {
+ fn realize(
+ &self,
+ world: Tracked<dyn World>,
+ styles: StyleChain,
+ ) -> SourceResult<Content> {
let mut cells = vec![];
let mut number = self.start;
@@ -145,7 +149,7 @@ impl<const L: ListKind> Show for ListNode<L> {
fn finalize(
&self,
- _: &dyn World,
+ _: Tracked<dyn World>,
styles: StyleChain,
realized: Content,
) -> SourceResult<Content> {
@@ -208,7 +212,7 @@ impl Label {
/// Resolve the value based on the level.
pub fn resolve(
&self,
- world: &dyn World,
+ world: Tracked<dyn World>,
kind: ListKind,
number: usize,
) -> SourceResult<Content> {
diff --git a/src/library/structure/reference.rs b/src/library/structure/reference.rs
index 5d1dab38..0a9f4f9c 100644
--- a/src/library/structure/reference.rs
+++ b/src/library/structure/reference.rs
@@ -22,7 +22,7 @@ impl Show for RefNode {
}
}
- fn realize(&self, _: &dyn World, _: StyleChain) -> SourceResult<Content> {
+ fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> {
Ok(Content::Text(format_eco!("@{}", self.0)))
}
}
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs
index f1ca7e03..9f89cd2b 100644
--- a/src/library/structure/table.rs
+++ b/src/library/structure/table.rs
@@ -72,7 +72,11 @@ impl Show for TableNode {
}
}
- fn realize(&self, world: &dyn World, styles: StyleChain) -> SourceResult<Content> {
+ fn realize(
+ &self,
+ world: Tracked<dyn World>,
+ styles: StyleChain,
+ ) -> SourceResult<Content> {
let fill = styles.get(Self::FILL);
let stroke = styles.get(Self::STROKE).map(RawStroke::unwrap_or_default);
let padding = styles.get(Self::PADDING);
@@ -110,7 +114,7 @@ impl Show for TableNode {
fn finalize(
&self,
- _: &dyn World,
+ _: Tracked<dyn World>,
styles: StyleChain,
realized: Content,
) -> SourceResult<Content> {
@@ -129,7 +133,12 @@ pub enum Celled<T> {
impl<T: Cast + Clone> Celled<T> {
/// Resolve the value based on the cell position.
- pub fn resolve(&self, world: &dyn World, x: usize, y: usize) -> SourceResult<T> {
+ pub fn resolve(
+ &self,
+ world: Tracked<dyn World>,
+ x: usize,
+ y: usize,
+ ) -> SourceResult<T> {
Ok(match self {
Self::Value(value) => value.clone(),
Self::Func(func, span) => {