diff --git a/Cargo.lock b/Cargo.lock index ef58bf1ce..7eb9ac917 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -286,9 +286,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "comemo" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22bf2c21093020535dd771993fedae8dd55393a4258cca501a9b55a962d350a5" +checksum = "70b396e6f0a1a7d2c1d588fd8a255a8c30a8edeef65bc96b4afb3fdb8a8bf281" dependencies = [ "comemo-macros", "siphasher", @@ -296,9 +296,9 @@ dependencies = [ [[package]] name = "comemo-macros" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9faa23f4534253fa656b176ff524d5cd7306a6fed3048929f9cc01ab38ab5a5a" +checksum = "421c3e125e48959f3b6a18c0d266f3c228f6e28464c73cc44cff24e808fcda2d" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 8f440c58f..f68f60560 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ bench = false typst-macros = { path = "macros" } bitflags = "1" bytemuck = "1" -comemo = "0.2" +comemo = "0.2.1" ecow = "0.1" flate2 = "1" if_chain = "1" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 853579226..31d2dc97b 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -23,7 +23,7 @@ typst = { path = ".." } typst-library = { path = "../library" } chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } codespan-reporting = "0.11" -comemo = "0.2" +comemo = "0.2.1" dirs = "4" elsa = "1.7" memmap2 = "0.5" diff --git a/docs/Cargo.toml b/docs/Cargo.toml index cc991f13d..9baf76286 100644 --- a/docs/Cargo.toml +++ b/docs/Cargo.toml @@ -15,7 +15,7 @@ typst-library = { path = "../library" } unscanny = "0.1" include_dir = "0.7" pulldown-cmark = "0.9" -comemo = "0.2" +comemo = "0.2.1" serde = "1" serde_yaml = "0.8" heck = "0.4" diff --git a/library/Cargo.toml b/library/Cargo.toml index dca5076d1..971788057 100644 --- a/library/Cargo.toml +++ b/library/Cargo.toml @@ -16,7 +16,7 @@ bench = false [dependencies] typst = { path = ".." } -comemo = "0.2" +comemo = "0.2.1" csv = "1" ecow = "0.1" hayagriva = "0.3" diff --git a/src/model/content.rs b/src/model/content.rs index 2ce12a51f..fa189b119 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), + Child(Prehashed), 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]), diff --git a/src/model/styles.rs b/src/model/styles.rs index a841ca564..7fda52cf4 100644 --- a/src/model/styles.rs +++ b/src/model/styles.rs @@ -2,8 +2,10 @@ use std::any::{Any, TypeId}; use std::fmt::{self, Debug, Formatter, Write}; use std::iter; use std::mem; +use std::ptr; use std::sync::Arc; +use comemo::Prehashed; use ecow::{eco_format, eco_vec, EcoString, EcoVec}; use super::{Content, ElemFunc, Element, Introspector, Label, Location, Vt}; @@ -15,7 +17,7 @@ use crate::util::pretty_array_like; /// A list of style properties. #[derive(Default, PartialEq, Clone, Hash)] -pub struct Styles(EcoVec