diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst-cli/src/world.rs | 14 | ||||
| -rw-r--r-- | crates/typst-ide/src/lib.rs | 14 | ||||
| -rw-r--r-- | crates/typst-syntax/Cargo.toml | 2 | ||||
| -rw-r--r-- | crates/typst-syntax/src/source.rs | 16 | ||||
| -rw-r--r-- | crates/typst/src/lib.rs | 11 | ||||
| -rw-r--r-- | crates/typst/src/visualize/pattern.rs | 7 |
6 files changed, 31 insertions, 33 deletions
diff --git a/crates/typst-cli/src/world.rs b/crates/typst-cli/src/world.rs index 57aecd42..81fece2a 100644 --- a/crates/typst-cli/src/world.rs +++ b/crates/typst-cli/src/world.rs @@ -5,7 +5,6 @@ use std::sync::OnceLock; use std::{fmt, fs, io, mem}; use chrono::{DateTime, Datelike, FixedOffset, Local, Utc}; -use comemo::Prehashed; use ecow::{eco_format, EcoString}; use once_cell::sync::Lazy; use parking_lot::Mutex; @@ -13,6 +12,7 @@ use typst::diag::{FileError, FileResult}; use typst::foundations::{Bytes, Datetime, Dict, IntoValue}; use typst::syntax::{FileId, Source, VirtualPath}; use typst::text::{Font, FontBook}; +use typst::utils::LazyHash; use typst::{Library, World}; use typst_timing::{timed, TimingScope}; @@ -34,9 +34,9 @@ pub struct SystemWorld { /// The input path. main: FileId, /// Typst's standard library. - library: Prehashed<Library>, + library: LazyHash<Library>, /// Metadata about discovered fonts. - book: Prehashed<FontBook>, + book: LazyHash<FontBook>, /// Locations of and storage for lazily loaded fonts. fonts: Vec<FontSlot>, /// Maps file ids to source files and buffers. @@ -114,8 +114,8 @@ impl SystemWorld { workdir: std::env::current_dir().ok(), root, main, - library: Prehashed::new(library), - book: Prehashed::new(searcher.book), + library: LazyHash::new(library), + book: LazyHash::new(searcher.book), fonts: searcher.fonts, slots: Mutex::new(HashMap::new()), now, @@ -170,11 +170,11 @@ impl SystemWorld { } impl World for SystemWorld { - fn library(&self) -> &Prehashed<Library> { + fn library(&self) -> &LazyHash<Library> { &self.library } - fn book(&self) -> &Prehashed<FontBook> { + fn book(&self) -> &LazyHash<FontBook> { &self.book } diff --git a/crates/typst-ide/src/lib.rs b/crates/typst-ide/src/lib.rs index 3967aaad..117e75ab 100644 --- a/crates/typst-ide/src/lib.rs +++ b/crates/typst-ide/src/lib.rs @@ -93,12 +93,12 @@ fn summarize_font_family<'a>(variants: impl Iterator<Item = &'a FontInfo>) -> Ec #[cfg(test)] mod tests { - use comemo::Prehashed; use once_cell::sync::Lazy; use typst::diag::{FileError, FileResult}; use typst::foundations::{Bytes, Datetime}; use typst::syntax::{FileId, Source}; use typst::text::{Font, FontBook}; + use typst::utils::LazyHash; use typst::{Library, World}; /// A world for IDE testing. @@ -120,11 +120,11 @@ mod tests { } impl World for TestWorld { - fn library(&self) -> &Prehashed<Library> { + fn library(&self) -> &LazyHash<Library> { &self.base.library } - fn book(&self) -> &Prehashed<FontBook> { + fn book(&self) -> &LazyHash<FontBook> { &self.base.book } @@ -155,8 +155,8 @@ mod tests { /// Shared foundation of all test worlds. struct TestBase { - library: Prehashed<Library>, - book: Prehashed<FontBook>, + library: LazyHash<Library>, + book: LazyHash<FontBook>, fonts: Vec<Font>, } @@ -168,8 +168,8 @@ mod tests { .collect(); Self { - library: Prehashed::new(Library::default()), - book: Prehashed::new(FontBook::from_fonts(&fonts)), + library: LazyHash::new(Library::default()), + book: LazyHash::new(FontBook::from_fonts(&fonts)), fonts, } } diff --git a/crates/typst-syntax/Cargo.toml b/crates/typst-syntax/Cargo.toml index 001d405c..816f0d34 100644 --- a/crates/typst-syntax/Cargo.toml +++ b/crates/typst-syntax/Cargo.toml @@ -13,7 +13,7 @@ keywords = { workspace = true } readme = { workspace = true } [dependencies] -comemo = { workspace = true } +typst-utils = { workspace = true } ecow = { workspace = true } once_cell = { workspace = true } serde = { workspace = true } diff --git a/crates/typst-syntax/src/source.rs b/crates/typst-syntax/src/source.rs index a68a53da..a2ccb5bb 100644 --- a/crates/typst-syntax/src/source.rs +++ b/crates/typst-syntax/src/source.rs @@ -6,7 +6,7 @@ use std::iter::zip; use std::ops::Range; use std::sync::Arc; -use comemo::Prehashed; +use typst_utils::LazyHash; use crate::reparser::reparse; use crate::{is_newline, parse, FileId, LinkedNode, Span, SyntaxNode, VirtualPath}; @@ -24,8 +24,8 @@ pub struct Source(Arc<Repr>); #[derive(Clone)] struct Repr { id: FileId, - text: Prehashed<String>, - root: Prehashed<SyntaxNode>, + text: LazyHash<String>, + root: LazyHash<SyntaxNode>, lines: Vec<Line>, } @@ -37,8 +37,8 @@ impl Source { Self(Arc::new(Repr { id, lines: lines(&text), - text: Prehashed::new(text), - root: Prehashed::new(root), + text: LazyHash::new(text), + root: LazyHash::new(root), })) } @@ -117,7 +117,7 @@ impl Source { let inner = Arc::make_mut(&mut self.0); // Update the text itself. - inner.text.update(|text| text.replace_range(replace.clone(), with)); + inner.text.replace_range(replace.clone(), with); // Remove invalidated line starts. inner.lines.truncate(line + 1); @@ -135,9 +135,7 @@ impl Source { )); // Incrementally reparse the replaced range. - inner - .root - .update(|root| reparse(root, &inner.text, replace, with.len())) + reparse(&mut inner.root, &inner.text, replace, with.len()) } /// Get the length of the file in UTF-8 encoded bytes. diff --git a/crates/typst/src/lib.rs b/crates/typst/src/lib.rs index bb869bfd..aad474a1 100644 --- a/crates/typst/src/lib.rs +++ b/crates/typst/src/lib.rs @@ -59,7 +59,7 @@ pub use typst_utils as utils; use std::collections::HashSet; use std::ops::{Deref, Range}; -use comemo::{Prehashed, Track, Tracked, Validate}; +use comemo::{Track, Tracked, Validate}; use ecow::{EcoString, EcoVec}; use typst_timing::{timed, TimingScope}; @@ -75,6 +75,7 @@ use crate::model::Document; use crate::syntax::package::PackageSpec; use crate::syntax::{FileId, Source, Span}; use crate::text::{Font, FontBook}; +use crate::utils::LazyHash; use crate::visualize::Color; /// Compile a source file into a fully layouted document. @@ -194,10 +195,10 @@ pub trait World { /// The standard library. /// /// Can be created through `Library::build()`. - fn library(&self) -> &Prehashed<Library>; + fn library(&self) -> &LazyHash<Library>; /// Metadata about all known fonts. - fn book(&self) -> &Prehashed<FontBook>; + fn book(&self) -> &LazyHash<FontBook>; /// Access the main source file. fn main(&self) -> Source; @@ -234,11 +235,11 @@ pub trait World { macro_rules! delegate_for_ptr { ($W:ident for $ptr:ty) => { impl<$W: World> World for $ptr { - fn library(&self) -> &Prehashed<Library> { + fn library(&self) -> &LazyHash<Library> { self.deref().library() } - fn book(&self) -> &Prehashed<FontBook> { + fn book(&self) -> &LazyHash<FontBook> { self.deref().book() } diff --git a/crates/typst/src/visualize/pattern.rs b/crates/typst/src/visualize/pattern.rs index ed4d25ac..0f12b5d5 100644 --- a/crates/typst/src/visualize/pattern.rs +++ b/crates/typst/src/visualize/pattern.rs @@ -1,7 +1,6 @@ use std::hash::Hash; use std::sync::Arc; -use comemo::Prehashed; use ecow::{eco_format, EcoString}; use crate::diag::{bail, SourceResult}; @@ -9,7 +8,7 @@ use crate::engine::Engine; use crate::foundations::{func, repr, scope, ty, Content, Smart, StyleChain}; use crate::layout::{Abs, Axes, Frame, LayoutMultiple, Length, Regions, Size}; use crate::syntax::{Span, Spanned}; -use crate::utils::Numeric; +use crate::utils::{LazyHash, Numeric}; use crate::visualize::RelativeTo; use crate::World; @@ -102,7 +101,7 @@ pub struct Pattern(Arc<Repr>); #[derive(Debug, Clone, Eq, PartialEq, Hash)] struct Repr { /// The pattern's rendered content. - frame: Prehashed<Frame>, + frame: LazyHash<Frame>, /// The pattern's tile size. size: Size, /// The pattern's tile spacing. @@ -209,7 +208,7 @@ impl Pattern { Ok(Self(Arc::new(Repr { size: frame.size(), - frame: Prehashed::new(frame), + frame: LazyHash::new(frame), spacing: spacing.v.map(|l| l.abs), relative, }))) |
