perf: reduce memory allocations
This also changes `widget::column::with_children` and `widget::row::with_children` to take an `impl IntoIterator` instead of a `Vec`, like the `iced` variants of these functions do. This shouldn't be a breaking change since passing in a `Vec` will still compile and function exactly as before. (Using `iced::widget::Column::from_vec` or `iced::widget::Row::from_vec` isn't possible, since the elements of the `Vec` aren't checked, so the size of the resulting `Column` or `Row` won't adapt to the size of its children. Perhaps a new function could be added to mirror `iced`'s?)
This commit is contained in:
parent
840ef21e4d
commit
bd438a8581
20 changed files with 83 additions and 88 deletions
|
|
@ -147,12 +147,14 @@ pub mod column {
|
|||
#[must_use]
|
||||
/// A pre-allocated [`column`].
|
||||
pub fn with_capacity<'a, Message>(capacity: usize) -> Column<'a, Message> {
|
||||
Column::with_children(Vec::with_capacity(capacity))
|
||||
Column::with_capacity(capacity)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
/// A [`column`] that will be assigned a [`Vec`] of children.
|
||||
pub fn with_children<Message>(children: Vec<crate::Element<Message>>) -> Column<Message> {
|
||||
/// A [`column`] that will be assigned an [`Iterator`] of children.
|
||||
pub fn with_children<'a, Message>(
|
||||
children: impl IntoIterator<Item = crate::Element<'a, Message>>,
|
||||
) -> Column<'a, Message> {
|
||||
Column::with_children(children)
|
||||
}
|
||||
}
|
||||
|
|
@ -298,12 +300,14 @@ pub mod row {
|
|||
#[must_use]
|
||||
/// A pre-allocated [`row`].
|
||||
pub fn with_capacity<'a, Message>(capacity: usize) -> Row<'a, Message> {
|
||||
Row::with_children(Vec::with_capacity(capacity))
|
||||
Row::with_capacity(capacity)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
/// A [`row`] that will be assigned a [`Vec`] of children.
|
||||
pub fn with_children<Message>(children: Vec<crate::Element<Message>>) -> Row<Message> {
|
||||
/// A [`row`] that will be assigned an [`Iterator`] of children.
|
||||
pub fn with_children<'a, Message>(
|
||||
children: impl IntoIterator<Item = crate::Element<'a, Message>>,
|
||||
) -> Row<'a, Message> {
|
||||
Row::with_children(children)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue