diff options
author | 2024-04-01 17:14:39 +0200 | |
---|---|---|
committer | 2024-04-01 17:14:39 +0200 | |
commit | c30b4b0a1c9b191bcb65ae1732581b5c96b8bcfe (patch) | |
tree | e6e7b42852a2eaf1bcf4a757f217a4a3eda2642a /widget/src/row.rs | |
parent | b40db569a2369dbdc79e40dc700974c2f7ac8d4b (diff) | |
parent | db4b03a6599c5c131b0672431f0c5c4afb4ac8d2 (diff) | |
download | iced-c30b4b0a1c9b191bcb65ae1732581b5c96b8bcfe.tar.gz iced-c30b4b0a1c9b191bcb65ae1732581b5c96b8bcfe.tar.bz2 iced-c30b4b0a1c9b191bcb65ae1732581b5c96b8bcfe.zip |
Merge pull request #2362 from iced-rs/size-hint-for-row-columns
Use `Iterator::size_hint` to initialize `Column` and `Row` capacity
Diffstat (limited to 'widget/src/row.rs')
-rw-r--r-- | widget/src/row.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/widget/src/row.rs b/widget/src/row.rs index 47feff9c..fa352171 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -31,11 +31,18 @@ where Self::from_vec(Vec::new()) } + /// Creates a [`Row`] with the given capacity. + pub fn with_capacity(capacity: usize) -> Self { + Self::from_vec(Vec::with_capacity(capacity)) + } + /// Creates a [`Row`] 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 [`Row`] from an already allocated [`Vec`]. |