From 836f32e7697195a482b88883cbbe4a2dd986d8cb Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Wed, 8 Jul 2015 22:52:55 +0200 Subject: Use vec![elt; n] where possible The common pattern `iter::repeat(elt).take(n).collect::>()` 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.) --- src/libsyntax/print/pp.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/libsyntax/print') diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index ed9937c53f4..7c5a46465f5 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -61,7 +61,6 @@ use std::io; use std::string; -use std::iter::repeat; #[derive(Clone, Copy, PartialEq)] pub enum Breaks { @@ -166,9 +165,9 @@ pub fn mk_printer<'a>(out: Box, linewidth: usize) -> Printer<'a> { // fall behind. let n: usize = 3 * linewidth; debug!("mk_printer {}", linewidth); - let token: Vec = repeat(Token::Eof).take(n).collect(); - let size: Vec = repeat(0).take(n).collect(); - let scan_stack: Vec = repeat(0).take(n).collect(); + let token = vec![Token::Eof; n]; + let size = vec![0_isize; n]; + let scan_stack = vec![0_usize; n]; Printer { out: out, buf_len: n, -- cgit 1.4.1-3-g733a5