mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Prevent double allocation due to Content::sequence
(#5084)
This commit is contained in:
parent
63e6150ca1
commit
d03af848eb
@ -245,16 +245,14 @@ impl Content {
|
|||||||
|
|
||||||
/// Create a new sequence element from multiples elements.
|
/// Create a new sequence element from multiples elements.
|
||||||
pub fn sequence(iter: impl IntoIterator<Item = Self>) -> Self {
|
pub fn sequence(iter: impl IntoIterator<Item = Self>) -> Self {
|
||||||
let mut iter = iter.into_iter();
|
let vec: Vec<_> = iter.into_iter().collect();
|
||||||
let Some(first) = iter.next() else { return Self::empty() };
|
if vec.is_empty() {
|
||||||
let Some(second) = iter.next() else { return first };
|
Self::empty()
|
||||||
SequenceElem::new(
|
} else if vec.len() == 1 {
|
||||||
std::iter::once(first)
|
vec.into_iter().next().unwrap()
|
||||||
.chain(std::iter::once(second))
|
} else {
|
||||||
.chain(iter)
|
SequenceElem::new(vec).into()
|
||||||
.collect(),
|
}
|
||||||
)
|
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the contained element is of type `T`.
|
/// Whether the contained element is of type `T`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user