Skip to content

Commit 3d48823

Browse files
committed
Rollup merge of rust-lang#55827 - ljedrz:various_stashed, r=alexcrichton
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`
2 parents 7982beb + 0c08529 commit 3d48823

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
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/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/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)