File tree 1 file changed +4
-4
lines changed
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -450,7 +450,8 @@ impl<T> [T] {
450
450
// and `rem` is the remaining part of `n`.
451
451
452
452
// Using `Vec` to access `set_len()`.
453
- let mut buf = Vec :: with_capacity ( self . len ( ) . checked_mul ( n) . expect ( "capacity overflow" ) ) ;
453
+ let capacity = self . len ( ) . checked_mul ( n) . expect ( "capacity overflow" ) ;
454
+ let mut buf = Vec :: with_capacity ( capacity) ;
454
455
455
456
// `2^expn` repetition is done by doubling `buf` `expn`-times.
456
457
buf. extend ( self ) ;
@@ -476,7 +477,7 @@ impl<T> [T] {
476
477
477
478
// `rem` (`= n - 2^expn`) repetition is done by copying
478
479
// first `rem` repetitions from `buf` itself.
479
- let rem_len = self . len ( ) * n - buf. len ( ) ; // `self.len() * rem`
480
+ let rem_len = capacity - buf. len ( ) ; // `self.len() * rem`
480
481
if rem_len > 0 {
481
482
// `buf.extend(buf[0 .. rem_len])`:
482
483
unsafe {
@@ -487,8 +488,7 @@ impl<T> [T] {
487
488
rem_len,
488
489
) ;
489
490
// `buf.len() + rem_len` equals to `buf.capacity()` (`= self.len() * n`).
490
- let buf_cap = buf. capacity ( ) ;
491
- buf. set_len ( buf_cap) ;
491
+ buf. set_len ( capacity) ;
492
492
}
493
493
}
494
494
buf
You can’t perform that action at this time.
0 commit comments