diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-09-21 17:50:58 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-09-21 20:25:57 +0200 |
| commit | ddd3b6a82b8c0353c942bfba8b89ca5476eedc58 (patch) | |
| tree | a64c350f0f1f82152ff18cfb02fbfdbf39292672 /src/library/text | |
| parent | 3760748fddd3b793c79c370398a9d4a3fc5afc04 (diff) | |
Tracked memoization
Diffstat (limited to 'src/library/text')
| -rw-r--r-- | src/library/text/deco.rs | 6 | ||||
| -rw-r--r-- | src/library/text/link.rs | 4 | ||||
| -rw-r--r-- | src/library/text/mod.rs | 4 | ||||
| -rw-r--r-- | src/library/text/par.rs | 18 | ||||
| -rw-r--r-- | src/library/text/raw.rs | 8 | ||||
| -rw-r--r-- | src/library/text/repeat.rs | 2 | ||||
| -rw-r--r-- | src/library/text/shaping.rs | 12 | ||||
| -rw-r--r-- | src/library/text/shift.rs | 8 |
8 files changed, 37 insertions, 25 deletions
diff --git a/src/library/text/deco.rs b/src/library/text/deco.rs index 3d030d45..1242488b 100644 --- a/src/library/text/deco.rs +++ b/src/library/text/deco.rs @@ -48,7 +48,11 @@ impl<const L: DecoLine> Show for DecoNode<L> { dict! { "body" => Value::Content(self.0.clone()) } } - fn realize(&self, _: &dyn World, styles: StyleChain) -> SourceResult<Content> { + fn realize( + &self, + _: Tracked<dyn World>, + styles: StyleChain, + ) -> SourceResult<Content> { Ok(self.0.clone().styled(TextNode::DECO, Decoration { line: L, stroke: styles.get(Self::STROKE).unwrap_or_default(), diff --git a/src/library/text/link.rs b/src/library/text/link.rs index f89bbd67..c06fea55 100644 --- a/src/library/text/link.rs +++ b/src/library/text/link.rs @@ -64,7 +64,7 @@ impl Show for LinkNode { } } - fn realize(&self, _: &dyn World, _: StyleChain) -> SourceResult<Content> { + fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { Ok(self.body.clone().unwrap_or_else(|| match &self.dest { Destination::Url(url) => { let mut text = url.as_str(); @@ -80,7 +80,7 @@ impl Show for LinkNode { fn finalize( &self, - _: &dyn World, + _: Tracked<dyn World>, styles: StyleChain, mut realized: Content, ) -> SourceResult<Content> { diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs index 55b866cb..934f5e15 100644 --- a/src/library/text/mod.rs +++ b/src/library/text/mod.rs @@ -507,7 +507,7 @@ impl Show for StrongNode { dict! { "body" => Value::Content(self.0.clone()) } } - fn realize(&self, _: &dyn World, _: StyleChain) -> SourceResult<Content> { + fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { Ok(self.0.clone().styled(TextNode::BOLD, Toggle)) } } @@ -532,7 +532,7 @@ impl Show for EmphNode { dict! { "body" => Value::Content(self.0.clone()) } } - fn realize(&self, _: &dyn World, _: StyleChain) -> SourceResult<Content> { + fn realize(&self, _: Tracked<dyn World>, _: StyleChain) -> SourceResult<Content> { Ok(self.0.clone().styled(TextNode::ITALIC, Toggle)) } } diff --git a/src/library/text/par.rs b/src/library/text/par.rs index 00a1e034..6910c23a 100644 --- a/src/library/text/par.rs +++ b/src/library/text/par.rs @@ -64,7 +64,7 @@ impl ParNode { impl Layout for ParNode { fn layout( &self, - world: &dyn World, + world: Tracked<dyn World>, regions: &Regions, styles: StyleChain, ) -> SourceResult<Vec<Frame>> { @@ -496,7 +496,7 @@ fn collect<'a>( /// Prepare paragraph layout by shaping the whole paragraph and layouting all /// contained inline-level nodes. fn prepare<'a>( - world: &dyn World, + world: Tracked<dyn World>, par: &'a ParNode, text: &'a str, segments: Vec<(Segment<'a>, StyleChain<'a>)>, @@ -561,7 +561,7 @@ fn prepare<'a>( /// items for them. fn shape_range<'a>( items: &mut Vec<Item<'a>>, - world: &dyn World, + world: Tracked<dyn World>, bidi: &BidiInfo<'a>, range: Range, styles: StyleChain<'a>, @@ -627,7 +627,7 @@ fn shared_get<'a, K: Key<'a>>( /// Find suitable linebreaks. fn linebreak<'a>( p: &'a Preparation<'a>, - world: &dyn World, + world: Tracked<dyn World>, width: Length, ) -> Vec<Line<'a>> { match p.styles.get(ParNode::LINEBREAKS) { @@ -641,7 +641,7 @@ fn linebreak<'a>( /// very unbalanced line, but is fast and simple. fn linebreak_simple<'a>( p: &'a Preparation<'a>, - world: &dyn World, + world: Tracked<dyn World>, width: Length, ) -> Vec<Line<'a>> { let mut lines = vec![]; @@ -701,7 +701,7 @@ fn linebreak_simple<'a>( /// text. fn linebreak_optimized<'a>( p: &'a Preparation<'a>, - world: &dyn World, + world: Tracked<dyn World>, width: Length, ) -> Vec<Line<'a>> { /// The cost of a line or paragraph layout. @@ -914,7 +914,7 @@ impl Breakpoints<'_> { /// Create a line which spans the given range. fn line<'a>( p: &'a Preparation, - world: &dyn World, + world: Tracked<dyn World>, mut range: Range, mandatory: bool, hyphen: bool, @@ -1022,7 +1022,7 @@ fn line<'a>( /// Combine layouted lines into one frame per region. fn stack( p: &Preparation, - world: &dyn World, + world: Tracked<dyn World>, lines: &[Line], regions: &Regions, ) -> SourceResult<Vec<Frame>> { @@ -1072,7 +1072,7 @@ fn stack( /// Commit to a line and build its frame. fn commit( p: &Preparation, - world: &dyn World, + world: Tracked<dyn World>, line: &Line, regions: &Regions, width: Length, diff --git a/src/library/text/raw.rs b/src/library/text/raw.rs index 5bce2a90..e7c73a91 100644 --- a/src/library/text/raw.rs +++ b/src/library/text/raw.rs @@ -59,7 +59,11 @@ impl Show for RawNode { } } - fn realize(&self, _: &dyn World, styles: StyleChain) -> SourceResult<Content> { + fn realize( + &self, + _: Tracked<dyn World>, + styles: StyleChain, + ) -> SourceResult<Content> { let lang = styles.get(Self::LANG).as_ref().map(|s| s.to_lowercase()); let foreground = THEME .settings @@ -111,7 +115,7 @@ impl Show for RawNode { fn finalize( &self, - _: &dyn World, + _: Tracked<dyn World>, styles: StyleChain, mut realized: Content, ) -> SourceResult<Content> { diff --git a/src/library/text/repeat.rs b/src/library/text/repeat.rs index 78a21069..e3bae3fc 100644 --- a/src/library/text/repeat.rs +++ b/src/library/text/repeat.rs @@ -14,7 +14,7 @@ impl RepeatNode { impl Layout for RepeatNode { fn layout( &self, - world: &dyn World, + world: Tracked<dyn World>, regions: &Regions, styles: StyleChain, ) -> SourceResult<Vec<Frame>> { diff --git a/src/library/text/shaping.rs b/src/library/text/shaping.rs index c1d0341b..16989acf 100644 --- a/src/library/text/shaping.rs +++ b/src/library/text/shaping.rs @@ -80,7 +80,7 @@ impl<'a> ShapedText<'a> { /// /// The `justification` defines how much extra advance width each /// [justifiable glyph](ShapedGlyph::is_justifiable) will get. - pub fn build(&self, world: &dyn World, justification: Length) -> Frame { + pub fn build(&self, world: Tracked<dyn World>, justification: Length) -> Frame { let (top, bottom) = self.measure(world); let size = Size::new(self.width, top + bottom); @@ -144,7 +144,7 @@ impl<'a> ShapedText<'a> { } /// Measure the top and bottom extent of this text. - fn measure(&self, world: &dyn World) -> (Length, Length) { + fn measure(&self, world: Tracked<dyn World>) -> (Length, Length) { let mut top = Length::zero(); let mut bottom = Length::zero(); @@ -199,7 +199,7 @@ impl<'a> ShapedText<'a> { /// shaping process if possible. pub fn reshape( &'a self, - world: &dyn World, + world: Tracked<dyn World>, text_range: Range<usize>, ) -> ShapedText<'a> { if let Some(glyphs) = self.slice_safe_to_break(text_range.clone()) { @@ -218,7 +218,7 @@ impl<'a> ShapedText<'a> { } /// Push a hyphen to end of the text. - pub fn push_hyphen(&mut self, world: &dyn World) { + pub fn push_hyphen(&mut self, world: Tracked<dyn World>) { families(self.styles).find_map(|family| { let font = world .book() @@ -306,7 +306,7 @@ impl Debug for ShapedText<'_> { /// Holds shaping results and metadata common to all shaped segments. struct ShapingContext<'a> { - world: &'a dyn World, + world: Tracked<'a, dyn World>, glyphs: Vec<ShapedGlyph>, used: Vec<Font>, styles: StyleChain<'a>, @@ -319,7 +319,7 @@ struct ShapingContext<'a> { /// Shape text into [`ShapedText`]. pub fn shape<'a>( - world: &dyn World, + world: Tracked<dyn World>, text: &'a str, styles: StyleChain<'a>, dir: Dir, diff --git a/src/library/text/shift.rs b/src/library/text/shift.rs index b359c5ed..6a5415e8 100644 --- a/src/library/text/shift.rs +++ b/src/library/text/shift.rs @@ -42,7 +42,11 @@ impl<const S: ScriptKind> Show for ShiftNode<S> { dict! { "body" => Value::Content(self.0.clone()) } } - fn realize(&self, world: &dyn World, styles: StyleChain) -> SourceResult<Content> { + fn realize( + &self, + world: Tracked<dyn World>, + styles: StyleChain, + ) -> SourceResult<Content> { let mut transformed = None; if styles.get(Self::TYPOGRAPHIC) { if let Some(text) = search_text(&self.0, S) { @@ -91,7 +95,7 @@ fn search_text(content: &Content, mode: ScriptKind) -> Option<EcoString> { /// Checks whether the first retrievable family contains all code points of the /// given string. -fn is_shapable(world: &dyn World, text: &str, styles: StyleChain) -> bool { +fn is_shapable(world: Tracked<dyn World>, text: &str, styles: StyleChain) -> bool { for family in styles.get(TextNode::FAMILY).iter() { if let Some(font) = world .book() |
