mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Add LazyHash
to frame (#4090)
This commit is contained in:
parent
182508658d
commit
96b04a7e1a
@ -11,7 +11,7 @@ use crate::layout::{
|
|||||||
};
|
};
|
||||||
use crate::syntax::Span;
|
use crate::syntax::Span;
|
||||||
use crate::text::TextItem;
|
use crate::text::TextItem;
|
||||||
use crate::util::Numeric;
|
use crate::util::{LazyHash, Numeric};
|
||||||
use crate::visualize::{
|
use crate::visualize::{
|
||||||
ellipse, styled_rect, Color, FixedStroke, Geometry, Image, Paint, Path, Shape,
|
ellipse, styled_rect, Color, FixedStroke, Geometry, Image, Paint, Path, Shape,
|
||||||
};
|
};
|
||||||
@ -25,7 +25,7 @@ pub struct Frame {
|
|||||||
/// frame's implicit baseline is at the bottom.
|
/// frame's implicit baseline is at the bottom.
|
||||||
baseline: Option<Abs>,
|
baseline: Option<Abs>,
|
||||||
/// The items composing this layout.
|
/// The items composing this layout.
|
||||||
items: Arc<Vec<(Point, FrameItem)>>,
|
items: Arc<LazyHash<Vec<(Point, FrameItem)>>>,
|
||||||
/// The hardness of this frame.
|
/// The hardness of this frame.
|
||||||
kind: FrameKind,
|
kind: FrameKind,
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ impl Frame {
|
|||||||
Self {
|
Self {
|
||||||
size,
|
size,
|
||||||
baseline: None,
|
baseline: None,
|
||||||
items: Arc::new(vec![]),
|
items: Arc::new(LazyHash::new(vec![])),
|
||||||
kind,
|
kind,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ impl Frame {
|
|||||||
let sink = Arc::make_mut(&mut self.items);
|
let sink = Arc::make_mut(&mut self.items);
|
||||||
match Arc::try_unwrap(frame.items) {
|
match Arc::try_unwrap(frame.items) {
|
||||||
Ok(items) => {
|
Ok(items) => {
|
||||||
sink.splice(range, items);
|
sink.splice(range, items.into_inner());
|
||||||
}
|
}
|
||||||
Err(arc) => {
|
Err(arc) => {
|
||||||
sink.splice(range, arc.iter().cloned());
|
sink.splice(range, arc.iter().cloned());
|
||||||
@ -235,7 +235,10 @@ impl Frame {
|
|||||||
let sink = Arc::make_mut(&mut self.items);
|
let sink = Arc::make_mut(&mut self.items);
|
||||||
match Arc::try_unwrap(frame.items) {
|
match Arc::try_unwrap(frame.items) {
|
||||||
Ok(items) => {
|
Ok(items) => {
|
||||||
sink.splice(range, items.into_iter().map(|(p, e)| (p + pos, e)));
|
sink.splice(
|
||||||
|
range,
|
||||||
|
items.into_inner().into_iter().map(|(p, e)| (p + pos, e)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(arc) => {
|
Err(arc) => {
|
||||||
sink.splice(range, arc.iter().cloned().map(|(p, e)| (p + pos, e)));
|
sink.splice(range, arc.iter().cloned().map(|(p, e)| (p + pos, e)));
|
||||||
@ -251,7 +254,7 @@ impl Frame {
|
|||||||
if Arc::strong_count(&self.items) == 1 {
|
if Arc::strong_count(&self.items) == 1 {
|
||||||
Arc::make_mut(&mut self.items).clear();
|
Arc::make_mut(&mut self.items).clear();
|
||||||
} else {
|
} else {
|
||||||
self.items = Arc::new(vec![]);
|
self.items = Arc::new(LazyHash::new(vec![]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +278,7 @@ impl Frame {
|
|||||||
if let Some(baseline) = &mut self.baseline {
|
if let Some(baseline) = &mut self.baseline {
|
||||||
*baseline += offset.y;
|
*baseline += offset.y;
|
||||||
}
|
}
|
||||||
for (point, _) in Arc::make_mut(&mut self.items) {
|
for (point, _) in Arc::make_mut(&mut self.items).iter_mut() {
|
||||||
*point += offset;
|
*point += offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user