Skip to content

Commit 01487a6

Browse files
committed
A few tweaks to iterations/collecting
1 parent 36a50c2 commit 01487a6

File tree

7 files changed

+16
-18
lines changed

7 files changed

+16
-18
lines changed

src/librustc/cfg/graphviz.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ impl<'a> dot::GraphWalk<'a> for &'a cfg::CFG {
106106
type Node = Node<'a>;
107107
type Edge = Edge<'a>;
108108
fn nodes(&'a self) -> dot::Nodes<'a, Node<'a>> {
109-
let mut v = Vec::new();
110-
self.graph.each_node(|i, nd| { v.push((i, nd)); true });
109+
let v: Vec<_> = self.graph.enumerated_nodes().collect();
111110
v.into()
112111
}
113112
fn edges(&'a self) -> dot::Edges<'a, Edge<'a>> {

src/librustc/dep_graph/graph.rs

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl DepGraph {
130130
let mut edges = Vec::new();
131131
for (index, edge_targets) in current_dep_graph.edges.iter_enumerated() {
132132
let from = current_dep_graph.nodes[index];
133+
edges.reserve(edge_targets.len());
133134
for &edge_target in edge_targets.iter() {
134135
let to = current_dep_graph.nodes[edge_target];
135136
edges.push((from, to));

src/librustc/hir/lowering.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,7 @@ impl<'a> LoweringContext<'a> {
10621062
attrs
10631063
.iter()
10641064
.map(|a| self.lower_attr(a))
1065-
.collect::<Vec<_>>()
1066-
.into()
1065+
.collect()
10671066
}
10681067

10691068
fn lower_attr(&mut self, attr: &Attribute) -> Attribute {

src/librustc/ty/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl<'sess> OnDiskCache<'sess> {
281281
// otherwise, abort
282282
break;
283283
}
284-
interpret_alloc_index.reserve(new_n);
284+
interpret_alloc_index.reserve(new_n - n);
285285
for idx in n..new_n {
286286
let id = encoder.interpret_allocs_inverse[idx];
287287
let pos = encoder.position() as u32;

src/librustc_mir/monomorphize/partitioning.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,8 @@ fn merge_codegen_units<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>,
608608

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

615615
let PreInliningPartitioning {
@@ -618,6 +618,7 @@ fn place_inlined_mono_items<'tcx>(initial_partitioning: PreInliningPartitioning<
618618
internalization_candidates,
619619
} = initial_partitioning;
620620

621+
let mut new_partitioning = Vec::with_capacity(initial_cgus.len());
621622
let single_codegen_unit = initial_cgus.len() == 1;
622623

623624
for old_codegen_unit in initial_cgus {

src/libserialize/hex.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl FromHex for str {
146146
}
147147

148148
match modulus {
149-
0 => Ok(b.into_iter().collect()),
149+
0 => Ok(b),
150150
_ => Err(InvalidHexLength),
151151
}
152152
}

src/libsyntax_ext/deriving/generic/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1200,16 +1200,14 @@ impl<'a> MethodDef<'a> {
12001200
let sp = trait_.span;
12011201
let variants = &enum_def.variants;
12021202

1203-
let self_arg_names = self_args.iter()
1204-
.enumerate()
1205-
.map(|(arg_count, _self_arg)| {
1206-
if arg_count == 0 {
1207-
"__self".to_string()
1208-
} else {
1203+
let self_arg_names = iter::once("__self".to_string()).chain(
1204+
self_args.iter()
1205+
.enumerate()
1206+
.skip(1)
1207+
.map(|(arg_count, _self_arg)|
12091208
format!("__arg_{}", arg_count)
1210-
}
1211-
})
1212-
.collect::<Vec<String>>();
1209+
)
1210+
).collect::<Vec<String>>();
12131211

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

0 commit comments

Comments
 (0)