mirror of
https://github.com/typst/typst
synced 2025-05-20 20:15:29 +08:00
Optimized DocumentElem
(#2777)
This commit is contained in:
parent
34862b7b27
commit
c1ed55f555
@ -724,7 +724,7 @@ impl<T> StyleVec<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> StyleVec<Cow<'a, Content>> {
|
impl<'a> StyleVec<Cow<'a, Content>> {
|
||||||
pub fn to_vec(self) -> Vec<Prehashed<Content>> {
|
pub fn to_vec<F: From<Content>>(self) -> Vec<F> {
|
||||||
self.items
|
self.items
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(
|
.zip(
|
||||||
@ -733,7 +733,7 @@ impl<'a> StyleVec<Cow<'a, Content>> {
|
|||||||
.flat_map(|(map, count)| iter::repeat(map).take(*count)),
|
.flat_map(|(map, count)| iter::repeat(map).take(*count)),
|
||||||
)
|
)
|
||||||
.map(|(content, styles)| content.into_owned().styled_with_map(styles.clone()))
|
.map(|(content, styles)| content.into_owned().styled_with_map(styles.clone()))
|
||||||
.map(Prehashed::new)
|
.map(F::from)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use comemo::Prehashed;
|
|
||||||
use ecow::EcoString;
|
use ecow::EcoString;
|
||||||
|
|
||||||
use crate::diag::{bail, SourceResult, StrResult};
|
use crate::diag::{bail, SourceResult, StrResult};
|
||||||
@ -32,12 +31,15 @@ pub struct DocumentElem {
|
|||||||
///
|
///
|
||||||
/// While this can be arbitrary content, PDF viewers only support plain text
|
/// While this can be arbitrary content, PDF viewers only support plain text
|
||||||
/// titles, so the conversion might be lossy.
|
/// titles, so the conversion might be lossy.
|
||||||
|
#[ghost]
|
||||||
pub title: Option<Content>,
|
pub title: Option<Content>,
|
||||||
|
|
||||||
/// The document's authors.
|
/// The document's authors.
|
||||||
|
#[ghost]
|
||||||
pub author: Author,
|
pub author: Author,
|
||||||
|
|
||||||
/// The document's keywords.
|
/// The document's keywords.
|
||||||
|
#[ghost]
|
||||||
pub keywords: Keywords,
|
pub keywords: Keywords,
|
||||||
|
|
||||||
/// The document's creation date.
|
/// The document's creation date.
|
||||||
@ -48,11 +50,12 @@ pub struct DocumentElem {
|
|||||||
///
|
///
|
||||||
/// The year component must be at least zero in order to be embedded into a
|
/// The year component must be at least zero in order to be embedded into a
|
||||||
/// PDF.
|
/// PDF.
|
||||||
|
#[ghost]
|
||||||
pub date: Smart<Option<Datetime>>,
|
pub date: Smart<Option<Datetime>>,
|
||||||
|
|
||||||
/// The page runs.
|
/// The page runs.
|
||||||
#[variadic]
|
#[variadic]
|
||||||
pub children: Vec<Prehashed<Content>>,
|
pub children: Vec<Content>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Construct for DocumentElem {
|
impl Construct for DocumentElem {
|
||||||
@ -71,11 +74,11 @@ impl LayoutRoot for DocumentElem {
|
|||||||
) -> SourceResult<Document> {
|
) -> SourceResult<Document> {
|
||||||
tracing::info!("Document layout");
|
tracing::info!("Document layout");
|
||||||
|
|
||||||
let mut pages = vec![];
|
let mut pages = Vec::with_capacity(self.children().len());
|
||||||
let mut page_counter = ManualPageCounter::new();
|
let mut page_counter = ManualPageCounter::new();
|
||||||
|
|
||||||
let children = self.children();
|
let children = self.children();
|
||||||
let mut iter = children.iter().map(|c| &**c).peekable();
|
let mut iter = children.iter().peekable();
|
||||||
|
|
||||||
while let Some(mut child) = iter.next() {
|
while let Some(mut child) = iter.next() {
|
||||||
let outer = styles;
|
let outer = styles;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user