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

@ -760,14 +760,14 @@ where
if state.dirty {
state.dirty = false;
let value = if self.is_secure {
self.value.secure()
&self.value.secure()
} else {
self.value.clone()
&self.value
};
replace_paragraph(
state,
Layout::new(&res),
&value,
value,
font,
iced::Pixels(size),
line_height,
@ -2022,7 +2022,7 @@ pub fn update<'a, Message: Clone + 'static>(
if let DndOfferState::HandlingOffer(mime_types, _action) = state.dnd_offer.clone() {
let Some(mime_type) = SUPPORTED_TEXT_MIME_TYPES
.iter()
.find(|m| mime_types.contains(&(**m).to_string()))
.find(|&&m| mime_types.iter().any(|t| t == m))
else {
state.dnd_offer = DndOfferState::None;
return event::Status::Captured;
@ -2057,7 +2057,7 @@ pub fn update<'a, Message: Clone + 'static>(
{
cold();
let state = state();
if let DndOfferState::Dropped = state.dnd_offer.clone() {
if matches!(&state.dnd_offer, DndOfferState::Dropped) {
state.dnd_offer = DndOfferState::None;
if !SUPPORTED_TEXT_MIME_TYPES.contains(&mime_type.as_str()) || data.is_empty() {
return event::Status::Captured;
@ -2536,7 +2536,7 @@ impl AsMimeTypes for TextInputString {
fn as_bytes(&self, mime_type: &str) -> Option<Cow<'static, [u8]>> {
if SUPPORTED_TEXT_MIME_TYPES.contains(&mime_type) {
Some(Cow::Owned(self.0.clone().as_bytes().to_vec()))
Some(Cow::Owned(self.0.clone().into_bytes()))
} else {
None
}