Skip to content

Commit

Permalink
Optimize IntoIter::extend for the likely-empty case.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Aug 23, 2022
1 parent ae882f2 commit 522d47f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,10 @@ impl<T> Extend<T> for ThinVec<T> {
I: IntoIterator<Item = T>,
{
let iter = iter.into_iter();
self.reserve(iter.size_hint().0);
let hint = iter.size_hint().0;
if hint > 0 {
self.reserve(hint);
}
for x in iter {
self.push(x);
}
Expand Down

0 comments on commit 522d47f

Please sign in to comment.