summaryrefslogtreecommitdiffstats
path: root/widget/src/column.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-04-01 16:08:14 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-04-01 16:08:42 +0200
commitdb4b03a6599c5c131b0672431f0c5c4afb4ac8d2 (patch)
treee6e7b42852a2eaf1bcf4a757f217a4a3eda2642a /widget/src/column.rs
parentb40db569a2369dbdc79e40dc700974c2f7ac8d4b (diff)
downloadiced-db4b03a6599c5c131b0672431f0c5c4afb4ac8d2.tar.gz
iced-db4b03a6599c5c131b0672431f0c5c4afb4ac8d2.tar.bz2
iced-db4b03a6599c5c131b0672431f0c5c4afb4ac8d2.zip
Use `Iterator::size_hint` to initialize `Column` and `Row` capacity
Diffstat (limited to 'widget/src/column.rs')
-rw-r--r--widget/src/column.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/widget/src/column.rs b/widget/src/column.rs
index d37ef695..df7829b3 100644
--- a/widget/src/column.rs
+++ b/widget/src/column.rs
@@ -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`].