@@ -2355,7 +2355,7 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
2355
2355
let len = self . len ( ) ;
2356
2356
2357
2357
if new_len > len {
2358
- self . extend_with ( new_len - len, ExtendElement ( value) )
2358
+ self . extend_with ( new_len - len, value)
2359
2359
} else {
2360
2360
self . truncate ( new_len) ;
2361
2361
}
@@ -2469,26 +2469,10 @@ impl<T, A: Allocator, const N: usize> Vec<[T; N], A> {
2469
2469
}
2470
2470
}
2471
2471
2472
- // This code generalizes `extend_with_{element,default}`.
2473
- trait ExtendWith < T > {
2474
- fn next ( & mut self ) -> T ;
2475
- fn last ( self ) -> T ;
2476
- }
2477
-
2478
- struct ExtendElement < T > ( T ) ;
2479
- impl < T : Clone > ExtendWith < T > for ExtendElement < T > {
2480
- fn next ( & mut self ) -> T {
2481
- self . 0 . clone ( )
2482
- }
2483
- fn last ( self ) -> T {
2484
- self . 0
2485
- }
2486
- }
2487
-
2488
- impl < T , A : Allocator > Vec < T , A > {
2472
+ impl < T : Clone , A : Allocator > Vec < T , A > {
2489
2473
#[ cfg( not( no_global_oom_handling) ) ]
2490
- /// Extend the vector by `n` values, using the given generator .
2491
- fn extend_with < E : ExtendWith < T > > ( & mut self , n : usize , mut value : E ) {
2474
+ /// Extend the vector by `n` clones of value .
2475
+ fn extend_with ( & mut self , n : usize , value : T ) {
2492
2476
self . reserve ( n) ;
2493
2477
2494
2478
unsafe {
@@ -2500,15 +2484,15 @@ impl<T, A: Allocator> Vec<T, A> {
2500
2484
2501
2485
// Write all elements except the last one
2502
2486
for _ in 1 ..n {
2503
- ptr:: write ( ptr, value. next ( ) ) ;
2487
+ ptr:: write ( ptr, value. clone ( ) ) ;
2504
2488
ptr = ptr. add ( 1 ) ;
2505
- // Increment the length in every step in case next () panics
2489
+ // Increment the length in every step in case clone () panics
2506
2490
local_len. increment_len ( 1 ) ;
2507
2491
}
2508
2492
2509
2493
if n > 0 {
2510
2494
// We can write the last element directly without cloning needlessly
2511
- ptr:: write ( ptr, value. last ( ) ) ;
2495
+ ptr:: write ( ptr, value) ;
2512
2496
local_len. increment_len ( 1 ) ;
2513
2497
}
2514
2498
0 commit comments