Skip to content

Commit a8954f1

Browse files
committed
Stop peeling the last iteration of the loop in Vec::repeat_with
1 parent 1c966e7 commit a8954f1

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

library/alloc/src/vec/mod.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,7 @@ impl<T, A: Allocator> Vec<T, A> {
21632163
{
21642164
let len = self.len();
21652165
if new_len > len {
2166-
self.extend_with(new_len - len, ExtendFunc(f));
2166+
self.extend_trusted(iter::repeat_with(f).take(new_len - len));
21672167
} else {
21682168
self.truncate(new_len);
21692169
}
@@ -2491,16 +2491,6 @@ impl<T: Clone> ExtendWith<T> for ExtendElement<T> {
24912491
}
24922492
}
24932493

2494-
struct ExtendFunc<F>(F);
2495-
impl<T, F: FnMut() -> T> ExtendWith<T> for ExtendFunc<F> {
2496-
fn next(&mut self) -> T {
2497-
(self.0)()
2498-
}
2499-
fn last(mut self) -> T {
2500-
(self.0)()
2501-
}
2502-
}
2503-
25042494
impl<T, A: Allocator> Vec<T, A> {
25052495
#[cfg(not(no_global_oom_handling))]
25062496
/// Extend the vector by `n` values, using the given generator.

0 commit comments

Comments
 (0)