Skip to content

Commit

Permalink
Auto merge of #55827 - ljedrz:various_stashed, r=<try>
Browse files Browse the repository at this point in the history
A few tweaks to iterations/collecting

- simplify and speed up `dot::GraphWalk::nodes` for `cfg::CFG`
- `reserve` the capacity for `edges` in `DepGraph::query`
- collect directly to a `HirVec` in `LoweringContext::lower_attrs`
- fix overallocation in `OnDiskCache::serialize`
- preallocate the `new_partitioning` vector in `merge_codegen_units`
- simplify `impl FromHex for str`
- improve the creation of `self_arg_names` in `impl MethodDef`
  • Loading branch information
bors committed Nov 12, 2018
2 parents 0195812 + 01487a6 commit f632eed
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/librustc/cfg/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ impl<'a> dot::GraphWalk<'a> for &'a cfg::CFG {
type Node = Node<'a>;
type Edge = Edge<'a>;
fn nodes(&'a self) -> dot::Nodes<'a, Node<'a>> {
let mut v = Vec::new();
self.graph.each_node(|i, nd| { v.push((i, nd)); true });
let v: Vec<_> = self.graph.enumerated_nodes().collect();
v.into()
}
fn edges(&'a self) -> dot::Edges<'a, Edge<'a>> {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl DepGraph {
let mut edges = Vec::new();
for (index, edge_targets) in current_dep_graph.edges.iter_enumerated() {
let from = current_dep_graph.nodes[index];
edges.reserve(edge_targets.len());
for &edge_target in edge_targets.iter() {
let to = current_dep_graph.nodes[edge_target];
edges.push((from, to));
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,7 @@ impl<'a> LoweringContext<'a> {
attrs
.iter()
.map(|a| self.lower_attr(a))
.collect::<Vec<_>>()
.into()
.collect()
}

fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<'sess> OnDiskCache<'sess> {
// otherwise, abort
break;
}
interpret_alloc_index.reserve(new_n);
interpret_alloc_index.reserve(new_n - n);
for idx in n..new_n {
let id = encoder.interpret_allocs_inverse[idx];
let pos = encoder.position() as u32;
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_mir/monomorphize/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ fn merge_codegen_units<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>,

fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning<'tcx>,
inlining_map: &InliningMap<'tcx>)
-> PostInliningPartitioning<'tcx> {
let mut new_partitioning = Vec::new();
-> PostInliningPartitioning<'tcx>
{
let mut mono_item_placements = FxHashMap::default();

let PreInliningPartitioning {
Expand All @@ -618,6 +618,7 @@ fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning<
internalization_candidates,
} = initial_partitioning;

let mut new_partitioning = Vec::with_capacity(initial_cgus.len());
let single_codegen_unit = initial_cgus.len() == 1;

for old_codegen_unit in initial_cgus {
Expand Down
2 changes: 1 addition & 1 deletion src/libserialize/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl FromHex for str {
}

match modulus {
0 => Ok(b.into_iter().collect()),
0 => Ok(b),
_ => Err(InvalidHexLength),
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/libsyntax_ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,16 +1200,14 @@ impl<'a> MethodDef<'a> {
let sp = trait_.span;
let variants = &enum_def.variants;

let self_arg_names = self_args.iter()
.enumerate()
.map(|(arg_count, _self_arg)| {
if arg_count == 0 {
"__self".to_string()
} else {
let self_arg_names = iter::once("__self".to_string()).chain(
self_args.iter()
.enumerate()
.skip(1)
.map(|(arg_count, _self_arg)|
format!("__arg_{}", arg_count)
}
})
.collect::<Vec<String>>();
)
).collect::<Vec<String>>();

let self_arg_idents = self_arg_names.iter()
.map(|name| cx.ident_of(&name[..]))
Expand All @@ -1218,7 +1216,7 @@ impl<'a> MethodDef<'a> {
// The `vi_idents` will be bound, solely in the catch-all, to
// a series of let statements mapping each self_arg to an int
// value corresponding to its discriminant.
let vi_idents: Vec<ast::Ident> = self_arg_names.iter()
let vi_idents = self_arg_names.iter()
.map(|name| {
let vi_suffix = format!("{}_vi", &name[..]);
cx.ident_of(&vi_suffix[..]).gensym()
Expand Down

0 comments on commit f632eed

Please sign in to comment.