Skip to content

Commit a7f2bb6

Browse files
committed
Reserve space in advance
1 parent 2ca0b85 commit a7f2bb6

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl TokenStream {
221221
}
222222
}
223223
if let Some((pos, comma, sp)) = suggestion {
224-
let mut new_stream = vec![];
224+
let mut new_stream = Vec::with_capacity(self.0.len() + 1);
225225
let parts = self.0.split_at(pos + 1);
226226
new_stream.extend_from_slice(parts.0);
227227
new_stream.push(comma);

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,17 +2011,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20112011
//
20122012
// For the "output" lifetime parameters, we just want to
20132013
// generate `'_`.
2014-
let mut generic_args: Vec<_> = lifetime_params[..input_lifetimes_count]
2015-
.iter()
2016-
.map(|&(span, hir_name)| {
2014+
let mut generic_args = Vec::with_capacity(lifetime_params.len());
2015+
generic_args.extend(lifetime_params[..input_lifetimes_count].iter().map(
2016+
|&(span, hir_name)| {
20172017
// Input lifetime like `'a` or `'1`:
20182018
GenericArg::Lifetime(hir::Lifetime {
20192019
hir_id: self.next_id(),
20202020
span,
20212021
name: hir::LifetimeName::Param(hir_name),
20222022
})
2023-
})
2024-
.collect();
2023+
},
2024+
));
20252025
generic_args.extend(lifetime_params[input_lifetimes_count..].iter().map(|&(span, _)|
20262026
// Output lifetime like `'_`.
20272027
GenericArg::Lifetime(hir::Lifetime {

compiler/rustc_builtin_macros/src/deriving/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
6666

6767
let fmt = substr.nonself_args[0].clone();
6868

69-
let mut stmts = vec![];
69+
let mut stmts = Vec::with_capacity(fields.len() + 2);
7070
match vdata {
7171
ast::VariantData::Tuple(..) | ast::VariantData::Unit(..) => {
7272
// tuple struct/"normal" variant

compiler/rustc_lint/src/levels.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> LintLevelMap {
3030
let mut builder = LintLevelMapBuilder { levels, tcx, store };
3131
let krate = tcx.hir().krate();
3232

33+
builder.levels.id_to_set.reserve(krate.exported_macros.len() + 1);
34+
3335
let push = builder.levels.push(&krate.item.attrs, &store, true);
3436
builder.levels.register_id(hir::CRATE_HIR_ID);
3537
for macro_def in krate.exported_macros {

0 commit comments

Comments
 (0)