diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-05-13 19:54:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-13 17:54:34 +0000 |
| commit | 2d32ac73b63c81ea2754916feb7758c042f4ed3d (patch) | |
| tree | c9770897cbb1134187132d6835702a1869a74a0a /crates/typst-syntax/src/source.rs | |
| parent | 95cd6adf24cb14ede8896fbb0c610432960f4f3a (diff) | |
Replace all `Prehashed` with `LazyHash` (#4127)
Diffstat (limited to 'crates/typst-syntax/src/source.rs')
| -rw-r--r-- | crates/typst-syntax/src/source.rs | 16 |
1 files changed, 7 insertions, 9 deletions
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. |
