File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -450,7 +450,8 @@ impl<T> [T] {
450450 // and `rem` is the remaining part of `n`.
451451
452452 // 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) ;
454455
455456 // `2^expn` repetition is done by doubling `buf` `expn`-times.
456457 buf. extend ( self ) ;
@@ -476,7 +477,7 @@ impl<T> [T] {
476477
477478 // `rem` (`= n - 2^expn`) repetition is done by copying
478479 // 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`
480481 if rem_len > 0 {
481482 // `buf.extend(buf[0 .. rem_len])`:
482483 unsafe {
@@ -487,8 +488,7 @@ impl<T> [T] {
487488 rem_len,
488489 ) ;
489490 // `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) ;
492492 }
493493 }
494494 buf
You can’t perform that action at this time.
0 commit comments