diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2015-07-08 22:52:55 +0200 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2015-07-09 11:05:32 +0200 |
| commit | 836f32e7697195a482b88883cbbe4a2dd986d8cb (patch) | |
| tree | f5855686978ec62f571011b78f1345a93ddd44e7 /src/libcoretest | |
| parent | 5b6a4643583c2b580b9a57f48dd94ba5d7824765 (diff) | |
| download | rust-836f32e7697195a482b88883cbbe4a2dd986d8cb.tar.gz rust-836f32e7697195a482b88883cbbe4a2dd986d8cb.zip | |
Use vec![elt; n] where possible
The common pattern `iter::repeat(elt).take(n).collect::<Vec<_>>()` is exactly equivalent to `vec![elt; n]`, do this replacement in the whole tree. (Actually, vec![] is smart enough to only call clone n - 1 times, while the former solution would call clone n times, and this fact is virtually irrelevant in practice.)
Diffstat (limited to 'src/libcoretest')
| -rw-r--r-- | src/libcoretest/ptr.rs | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/libcoretest/ptr.rs b/src/libcoretest/ptr.rs index 8f1017c50a3..865b049aae5 100644 --- a/src/libcoretest/ptr.rs +++ b/src/libcoretest/ptr.rs @@ -10,7 +10,6 @@ use core::ptr::*; use core::mem; -use std::iter::repeat; #[test] fn test() { @@ -110,7 +109,7 @@ fn test_as_mut() { #[test] fn test_ptr_addition() { unsafe { - let xs = repeat(5).take(16).collect::<Vec<_>>(); + let xs = vec![5; 16]; let mut ptr = xs.as_ptr(); let end = ptr.offset(16); @@ -128,7 +127,7 @@ fn test_ptr_addition() { m_ptr = m_ptr.offset(1); } - assert!(xs_mut == repeat(10).take(16).collect::<Vec<_>>()); + assert!(xs_mut == vec![10; 16]); } } |
