diff options
| author | bors <bors@rust-lang.org> | 2015-07-09 10:36:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-07-09 10:36:41 +0000 |
| commit | f11502cda8a05aae9b260141ac9c4538d46bb01b (patch) | |
| tree | fd3a72c4bf63d6d12a48155843dd172af01a6a70 /src/libsyntax | |
| parent | 517e087c16749086a3a0fec453af3d1c53232605 (diff) | |
| parent | 836f32e7697195a482b88883cbbe4a2dd986d8cb (diff) | |
| download | rust-f11502cda8a05aae9b260141ac9c4538d46bb01b.tar.gz rust-f11502cda8a05aae9b260141ac9c4538d46bb01b.zip | |
Auto merge of #26904 - bluss:no-repeat, r=alexcrichton
In a followup to PR #26849, improve one more location for I/O where we can use `Vec::resize` to ensure better performance when zeroing buffers. Use the `vec![elt; n]` macro everywhere we can in the tree. It replaces `repeat(elt).take(n).collect()` which is more verbose, requires type hints, and right now produces worse code. `vec![]` is preferable for vector initialization. The `vec![]` replacement touches upon one I/O path too, Stdin::read for windows, and that should be a small improvement. r? @alexcrichton
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/format.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/print/pp.rs | 7 |
2 files changed, 4 insertions, 6 deletions
diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 86e72d4ef03..5b972b464c9 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -23,7 +23,6 @@ use parse::token; use ptr::P; use std::collections::HashMap; -use std::iter::repeat; #[derive(PartialEq)] enum ArgumentType { @@ -469,7 +468,7 @@ impl<'a, 'b> Context<'a, 'b> { /// to fn into_expr(mut self) -> P<ast::Expr> { let mut locals = Vec::new(); - let mut names: Vec<_> = repeat(None).take(self.name_positions.len()).collect(); + let mut names = vec![None; self.name_positions.len()]; let mut pats = Vec::new(); let mut heads = Vec::new(); 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<io::Write+'a>, linewidth: usize) -> Printer<'a> { // fall behind. let n: usize = 3 * linewidth; debug!("mk_printer {}", linewidth); - let token: Vec<Token> = repeat(Token::Eof).take(n).collect(); - let size: Vec<isize> = repeat(0).take(n).collect(); - let scan_stack: Vec<usize> = 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, |
