diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2019-12-28 00:35:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-28 00:35:59 +0100 |
| commit | a076464c4a7e7e41be221ff3e05dbf22798be2bc (patch) | |
| tree | 1cc3d1fd7b16cbf7393dc7adeb83839f2cb586e9 /src/liballoc | |
| parent | b1b005b8f0d5219bc2020b902390508b5858baee (diff) | |
| parent | 3c56a65bc42fa83edbcdfdb5357e99c5557755cb (diff) | |
| download | rust-a076464c4a7e7e41be221ff3e05dbf22798be2bc.tar.gz rust-a076464c4a7e7e41be221ff3e05dbf22798be2bc.zip | |
Rollup merge of #67576 - king6cong:slice_repeat, r=Dylan-DPC
reuse `capacity` variable in slice::repeat None
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/slice.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 2f6d10c027b..7b83658fca6 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -450,7 +450,8 @@ impl<T> [T] { // and `rem` is the remaining part of `n`. // Using `Vec` to access `set_len()`. - let mut buf = Vec::with_capacity(self.len().checked_mul(n).expect("capacity overflow")); + let capacity = self.len().checked_mul(n).expect("capacity overflow"); + let mut buf = Vec::with_capacity(capacity); // `2^expn` repetition is done by doubling `buf` `expn`-times. buf.extend(self); @@ -476,7 +477,7 @@ impl<T> [T] { // `rem` (`= n - 2^expn`) repetition is done by copying // first `rem` repetitions from `buf` itself. - let rem_len = self.len() * n - buf.len(); // `self.len() * rem` + let rem_len = capacity - buf.len(); // `self.len() * rem` if rem_len > 0 { // `buf.extend(buf[0 .. rem_len])`: unsafe { @@ -487,8 +488,7 @@ impl<T> [T] { rem_len, ); // `buf.len() + rem_len` equals to `buf.capacity()` (`= self.len() * n`). - let buf_cap = buf.capacity(); - buf.set_len(buf_cap); + buf.set_len(capacity); } } buf |
