Skip to content

Commit

Permalink
Merge pull request #254 from barskern/tabs-prevent-allocation
Browse files Browse the repository at this point in the history
Use IntoIterator instead of Vec for tabs
  • Loading branch information
genusistimelord authored Jul 3, 2024
2 parents 6bbeba5 + 26dfdef commit dfa670d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/widgets/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ where
/// * the function that will be called if a tab is selected by the user.
/// It takes the index of the selected tab.
pub fn new_with_tabs<F>(
tabs: Vec<(TabId, TabLabel, Element<'a, Message, Theme, Renderer>)>,
tabs: impl IntoIterator<Item = (TabId, TabLabel, Element<'a, Message, Theme, Renderer>)>,
on_select: F,
) -> Self
where
F: 'static + Fn(TabId) -> Message,
{
let mut tab_labels = Vec::with_capacity(tabs.len());
let mut elements = Vec::with_capacity(tabs.len());
let mut indices = Vec::with_capacity(tabs.len());
let tabs = tabs.into_iter();
let n_tabs = tabs.size_hint().0;

let mut tab_labels = Vec::with_capacity(n_tabs);
let mut elements = Vec::with_capacity(n_tabs);
let mut indices = Vec::with_capacity(n_tabs);

for (id, tab_label, element) in tabs {
tab_labels.push((id.clone(), tab_label));
Expand Down

0 comments on commit dfa670d

Please sign in to comment.