diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-04-13 14:23:46 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-04-13 14:23:46 +0200 |
| commit | 89cf4054d61d296245b34a20f9ad0b749c0f83e2 (patch) | |
| tree | 38aaae4cf2a5e4b5f67e59d499f652c2eb3a372a /src/model/content.rs | |
| parent | f2732bb7b205361c5f309488b4e5235b4fc61e7c (diff) | |
Reduce amount of hashing
Diffstat (limited to 'src/model/content.rs')
| -rw-r--r-- | src/model/content.rs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/model/content.rs b/src/model/content.rs index 2ce12a51..fa189b11 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -3,7 +3,7 @@ use std::fmt::{self, Debug, Formatter, Write}; use std::iter::Sum; use std::ops::{Add, AddAssign}; -use comemo::Tracked; +use comemo::{Prehashed, Tracked}; use ecow::{eco_format, EcoString, EcoVec}; use super::{ @@ -29,8 +29,8 @@ pub struct Content { enum Attr { Span(Span), Field(EcoString), - Value(Value), - Child(Content), + Value(Prehashed<Value>), + Child(Prehashed<Content>), Styles(Styles), Prepared, Guard(Guard), @@ -54,9 +54,11 @@ impl Content { let Some(first) = iter.next() else { return Self::empty() }; let Some(second) = iter.next() else { return first }; let mut content = Content::empty(); - content.attrs.push(Attr::Child(first)); - content.attrs.push(Attr::Child(second)); - content.attrs.extend(iter.map(Attr::Child)); + content.attrs.push(Attr::Child(Prehashed::new(first))); + content.attrs.push(Attr::Child(Prehashed::new(second))); + content + .attrs + .extend(iter.map(|child| Attr::Child(Prehashed::new(child)))); content } @@ -164,10 +166,10 @@ impl Content { Attr::Field(field) => *field == name, _ => false, }) { - self.attrs.make_mut()[i + 1] = Attr::Value(value.into()); + self.attrs.make_mut()[i + 1] = Attr::Value(Prehashed::new(value.into())); } else { self.attrs.push(Attr::Field(name)); - self.attrs.push(Attr::Value(value.into())); + self.attrs.push(Attr::Value(Prehashed::new(value.into()))); } } @@ -285,7 +287,7 @@ impl Content { self } else { let mut content = Content::new(StyledElem::func()); - content.attrs.push(Attr::Child(self)); + content.attrs.push(Attr::Child(Prehashed::new(self))); content.attrs.push(Attr::Styles(styles)); content } @@ -466,11 +468,11 @@ impl Add for Content { lhs } (true, false) => { - lhs.attrs.push(Attr::Child(rhs)); + lhs.attrs.push(Attr::Child(Prehashed::new(rhs))); lhs } (false, true) => { - rhs.attrs.insert(0, Attr::Child(lhs)); + rhs.attrs.insert(0, Attr::Child(Prehashed::new(lhs))); rhs } (false, false) => Self::sequence([lhs, rhs]), |
