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:
Cheong Lau 2025-10-11 13:36:35 +10:00 committed by Michael Murphy
parent 840ef21e4d
commit bd438a8581
20 changed files with 83 additions and 88 deletions

View file

@ -1653,7 +1653,7 @@ fn get_children_layout<Message>(
let child_sizes: Vec<Size> = match item_height {
ItemHeight::Uniform(u) => {
let count = menu_tree.children.len();
(0..count).map(|_| Size::new(width, f32::from(u))).collect()
vec![Size::new(width, f32::from(u)); count]
}
ItemHeight::Static(s) => menu_tree
.children

View file

@ -144,7 +144,7 @@ where
Message: std::clone::Clone + 'a,
{
widget::button::custom(
widget::Row::with_children(children)
widget::Row::from_vec(children)
.align_y(Alignment::Center)
.height(Length::Fill)
.width(Length::Fill),
@ -252,7 +252,7 @@ pub fn menu_items<
let l: Cow<'static, str> = label.into();
let key = find_key(&action, key_binds);
let mut items = vec![
widget::text(l.clone()).into(),
widget::text(l).into(),
widget::horizontal_space().into(),
widget::text(key).class(key_class).into(),
];
@ -272,7 +272,7 @@ pub fn menu_items<
let key = find_key(&action, key_binds);
let mut items = vec![
widget::text(l.clone()).into(),
widget::text(l).into(),
widget::horizontal_space().into(),
widget::text(key).class(key_class).into(),
];