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
This commit is contained in:
commit
f11502cda8
32 changed files with 64 additions and 93 deletions
|
|
@ -704,7 +704,7 @@ fn is_useful(cx: &MatchCheckCtxt,
|
|||
match is_useful(cx, &matrix, v.tail(), witness) {
|
||||
UsefulWithWitness(pats) => {
|
||||
let arity = constructor_arity(cx, &constructor, left_ty);
|
||||
let wild_pats: Vec<_> = repeat(DUMMY_WILD_PAT).take(arity).collect();
|
||||
let wild_pats = vec![DUMMY_WILD_PAT; arity];
|
||||
let enum_pat = construct_witness(cx, &constructor, wild_pats, left_ty);
|
||||
let mut new_pats = vec![enum_pat];
|
||||
new_pats.extend(pats);
|
||||
|
|
@ -862,7 +862,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
|||
} = raw_pat(r[col]);
|
||||
let head: Option<Vec<&Pat>> = match *node {
|
||||
ast::PatWild(_) =>
|
||||
Some(repeat(DUMMY_WILD_PAT).take(arity).collect()),
|
||||
Some(vec![DUMMY_WILD_PAT; arity]),
|
||||
|
||||
ast::PatIdent(_, _, _) => {
|
||||
let opt_def = cx.tcx.def_map.borrow().get(&pat_id).map(|d| d.full_def());
|
||||
|
|
@ -875,7 +875,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
|||
} else {
|
||||
None
|
||||
},
|
||||
_ => Some(repeat(DUMMY_WILD_PAT).take(arity).collect())
|
||||
_ => Some(vec![DUMMY_WILD_PAT; arity])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -889,7 +889,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
|||
DefVariant(..) | DefStruct(..) => {
|
||||
Some(match args {
|
||||
&Some(ref args) => args.iter().map(|p| &**p).collect(),
|
||||
&None => repeat(DUMMY_WILD_PAT).take(arity).collect(),
|
||||
&None => vec![DUMMY_WILD_PAT; arity],
|
||||
})
|
||||
}
|
||||
_ => None
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ use middle::cfg::CFGIndex;
|
|||
use middle::ty;
|
||||
use std::io;
|
||||
use std::usize;
|
||||
use std::iter::repeat;
|
||||
use syntax::ast;
|
||||
use syntax::ast_util::IdRange;
|
||||
use syntax::visit;
|
||||
|
|
@ -239,11 +238,11 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
|
|||
|
||||
let entry = if oper.initial_value() { usize::MAX } else {0};
|
||||
|
||||
let zeroes: Vec<_> = repeat(0).take(num_nodes * words_per_id).collect();
|
||||
let gens: Vec<_> = zeroes.clone();
|
||||
let kills1: Vec<_> = zeroes.clone();
|
||||
let kills2: Vec<_> = zeroes;
|
||||
let on_entry: Vec<_> = repeat(entry).take(num_nodes * words_per_id).collect();
|
||||
let zeroes = vec![0; num_nodes * words_per_id];
|
||||
let gens = zeroes.clone();
|
||||
let kills1 = zeroes.clone();
|
||||
let kills2 = zeroes;
|
||||
let on_entry = vec![entry; num_nodes * words_per_id];
|
||||
|
||||
let nodeid_to_index = build_nodeid_to_index(decl, cfg);
|
||||
|
||||
|
|
@ -511,7 +510,7 @@ impl<'a, 'tcx, O:DataFlowOperator+Clone+'static> DataFlowContext<'a, 'tcx, O> {
|
|||
changed: true
|
||||
};
|
||||
|
||||
let mut temp: Vec<_> = repeat(0).take(words_per_id).collect();
|
||||
let mut temp = vec![0; words_per_id];
|
||||
while propcx.changed {
|
||||
propcx.changed = false;
|
||||
propcx.reset(&mut temp);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ use util::nodemap::{FnvHashMap, FnvHashSet};
|
|||
use std::cell::{Cell, RefCell};
|
||||
use std::cmp::Ordering::{self, Less, Greater, Equal};
|
||||
use std::fmt;
|
||||
use std::iter::repeat;
|
||||
use std::u32;
|
||||
use syntax::ast;
|
||||
|
||||
|
|
@ -1304,7 +1303,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
|||
// idea is to report errors that derive from independent
|
||||
// regions of the graph, but not those that derive from
|
||||
// overlapping locations.
|
||||
let mut dup_vec: Vec<_> = repeat(u32::MAX).take(self.num_vars() as usize).collect();
|
||||
let mut dup_vec = vec![u32::MAX; self.num_vars() as usize];
|
||||
|
||||
for idx in 0..self.num_vars() as usize {
|
||||
match var_data[idx].value {
|
||||
|
|
|
|||
|
|
@ -119,7 +119,6 @@ use util::nodemap::NodeMap;
|
|||
use std::{fmt, usize};
|
||||
use std::io::prelude::*;
|
||||
use std::io;
|
||||
use std::iter::repeat;
|
||||
use std::rc::Rc;
|
||||
use syntax::ast::{self, NodeId, Expr};
|
||||
use syntax::codemap::{BytePos, original_sp, Span};
|
||||
|
|
@ -566,8 +565,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||
Liveness {
|
||||
ir: ir,
|
||||
s: specials,
|
||||
successors: repeat(invalid_node()).take(num_live_nodes).collect(),
|
||||
users: repeat(invalid_users()).take(num_live_nodes * num_vars).collect(),
|
||||
successors: vec![invalid_node(); num_live_nodes],
|
||||
users: vec![invalid_users(); num_live_nodes * num_vars],
|
||||
loop_scope: Vec::new(),
|
||||
break_ln: NodeMap(),
|
||||
cont_ln: NodeMap(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue