Use Iterator::size_hint to initialize Column and Row capacity
This commit is contained in:
parent
b40db569a2
commit
db4b03a659
3 changed files with 56 additions and 8 deletions
|
|
@ -33,11 +33,18 @@ where
|
|||
Self::from_vec(Vec::new())
|
||||
}
|
||||
|
||||
/// Creates a [`Column`] with the given capacity.
|
||||
pub fn with_capacity(capacity: usize) -> Self {
|
||||
Self::from_vec(Vec::with_capacity(capacity))
|
||||
}
|
||||
|
||||
/// Creates a [`Column`] with the given elements.
|
||||
pub fn with_children(
|
||||
children: impl IntoIterator<Item = Element<'a, Message, Theme, Renderer>>,
|
||||
) -> Self {
|
||||
Self::new().extend(children)
|
||||
let iterator = children.into_iter();
|
||||
|
||||
Self::with_capacity(iterator.size_hint().0).extend(iterator)
|
||||
}
|
||||
|
||||
/// Creates a [`Column`] from an already allocated [`Vec`].
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue