mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Reserve space in advance
This commit is contained in:
parent
2ca0b85593
commit
a7f2bb6343
@ -221,7 +221,7 @@ impl TokenStream {
|
||||
}
|
||||
}
|
||||
if let Some((pos, comma, sp)) = suggestion {
|
||||
let mut new_stream = vec![];
|
||||
let mut new_stream = Vec::with_capacity(self.0.len() + 1);
|
||||
let parts = self.0.split_at(pos + 1);
|
||||
new_stream.extend_from_slice(parts.0);
|
||||
new_stream.push(comma);
|
||||
|
@ -2011,17 +2011,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
//
|
||||
// For the "output" lifetime parameters, we just want to
|
||||
// generate `'_`.
|
||||
let mut generic_args: Vec<_> = lifetime_params[..input_lifetimes_count]
|
||||
.iter()
|
||||
.map(|&(span, hir_name)| {
|
||||
let mut generic_args = Vec::with_capacity(lifetime_params.len());
|
||||
generic_args.extend(lifetime_params[..input_lifetimes_count].iter().map(
|
||||
|&(span, hir_name)| {
|
||||
// Input lifetime like `'a` or `'1`:
|
||||
GenericArg::Lifetime(hir::Lifetime {
|
||||
hir_id: self.next_id(),
|
||||
span,
|
||||
name: hir::LifetimeName::Param(hir_name),
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
},
|
||||
));
|
||||
generic_args.extend(lifetime_params[input_lifetimes_count..].iter().map(|&(span, _)|
|
||||
// Output lifetime like `'_`.
|
||||
GenericArg::Lifetime(hir::Lifetime {
|
||||
|
@ -66,7 +66,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
|
||||
|
||||
let fmt = substr.nonself_args[0].clone();
|
||||
|
||||
let mut stmts = vec![];
|
||||
let mut stmts = Vec::with_capacity(fields.len() + 2);
|
||||
match vdata {
|
||||
ast::VariantData::Tuple(..) | ast::VariantData::Unit(..) => {
|
||||
// tuple struct/"normal" variant
|
||||
|
@ -30,6 +30,8 @@ fn lint_levels(tcx: TyCtxt<'_>, cnum: CrateNum) -> LintLevelMap {
|
||||
let mut builder = LintLevelMapBuilder { levels, tcx, store };
|
||||
let krate = tcx.hir().krate();
|
||||
|
||||
builder.levels.id_to_set.reserve(krate.exported_macros.len() + 1);
|
||||
|
||||
let push = builder.levels.push(&krate.item.attrs, &store, true);
|
||||
builder.levels.register_id(hir::CRATE_HIR_ID);
|
||||
for macro_def in krate.exported_macros {
|
||||
|
Loading…
Reference in New Issue
Block a user