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/libstd/collections | |
| 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/libstd/collections')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 1dca3b77f38..06a30670e8b 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1638,7 +1638,7 @@ mod test_map { use super::HashMap; use super::Entry::{Occupied, Vacant}; - use iter::{range_inclusive, repeat}; + use iter::range_inclusive; use cell::RefCell; use rand::{thread_rng, Rng}; @@ -1698,7 +1698,7 @@ mod test_map { #[test] fn test_drops() { DROP_VECTOR.with(|slot| { - *slot.borrow_mut() = repeat(0).take(200).collect(); + *slot.borrow_mut() = vec![0; 200]; }); { @@ -1757,7 +1757,7 @@ mod test_map { #[test] fn test_move_iter_drops() { DROP_VECTOR.with(|v| { - *v.borrow_mut() = repeat(0).take(200).collect(); + *v.borrow_mut() = vec![0; 200]; }); let hm = { |
