mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Produce location variants more efficiently (#4096)
This commit is contained in:
parent
560791afe8
commit
4bca472210
@ -28,17 +28,19 @@ pub struct Location {
|
|||||||
/// An unique number among elements with the same hash. This is the reason
|
/// An unique number among elements with the same hash. This is the reason
|
||||||
/// we need a `Locator` everywhere.
|
/// we need a `Locator` everywhere.
|
||||||
pub disambiguator: usize,
|
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 {
|
impl Location {
|
||||||
/// Produce a variant of this location.
|
/// Produces a well-known variant of this location.
|
||||||
pub fn variant(mut self, n: usize) -> Self {
|
///
|
||||||
self.variant = n;
|
/// This is a synthetic location created from another one and is used, for
|
||||||
self
|
/// 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ impl<'a> Locator<'a> {
|
|||||||
self.hashes.get_mut().insert(hash, disambiguator + 1);
|
self.hashes.get_mut().insert(hash, disambiguator + 1);
|
||||||
|
|
||||||
// Create the location in its default variant.
|
// Create the location in its default variant.
|
||||||
Location { hash, disambiguator, variant: 0 }
|
Location { hash, disambiguator }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Advance past a frame.
|
/// Advance past a frame.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user