diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-05-08 12:54:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-08 10:54:58 +0000 |
| commit | 4bca472210d1863fcb638e9b641ddc2a1e9b1515 (patch) | |
| tree | e55750253d846b819c757471c65496ed879a4f91 | |
| parent | 560791afe84c87c9ef212b1e4289edc30ce50646 (diff) | |
Produce location variants more efficiently (#4096)
| -rw-r--r-- | crates/typst/src/introspection/location.rs | 18 | ||||
| -rw-r--r-- | crates/typst/src/introspection/locator.rs | 2 |
2 files changed, 11 insertions, 9 deletions
diff --git a/crates/typst/src/introspection/location.rs b/crates/typst/src/introspection/location.rs index 8cd49b07..4b02df6c 100644 --- a/crates/typst/src/introspection/location.rs +++ b/crates/typst/src/introspection/location.rs @@ -28,17 +28,19 @@ pub struct Location { /// An unique number among elements with the same hash. This is the reason /// we need a `Locator` everywhere. pub disambiguator: usize, - /// A synthetic location created from another one. This is used for example - /// in bibliography management to create individual linkable locations for - /// reference entries from the bibliography's location. - pub variant: usize, } impl Location { - /// Produce a variant of this location. - pub fn variant(mut self, n: usize) -> Self { - self.variant = n; - self + /// Produces a well-known variant of this location. + /// + /// This is a synthetic location created from another one and is used, for + /// example, in bibliography management to create individual linkable + /// locations for reference entries from the bibliography's location. + pub fn variant(self, n: usize) -> Self { + Self { + hash: crate::util::hash128(&(self.hash, n)), + ..self + } } } diff --git a/crates/typst/src/introspection/locator.rs b/crates/typst/src/introspection/locator.rs index 586f841d..7346b6fb 100644 --- a/crates/typst/src/introspection/locator.rs +++ b/crates/typst/src/introspection/locator.rs @@ -69,7 +69,7 @@ impl<'a> Locator<'a> { self.hashes.get_mut().insert(hash, disambiguator + 1); // Create the location in its default variant. - Location { hash, disambiguator, variant: 0 } + Location { hash, disambiguator } } /// Advance past a frame. |
