Rollup merge of #55542 - ljedrz:syntax_alloc_improvements, r=kennytm

syntax: improve a few allocations

Add 2 `reserve`s and a `with_capacity` where the final vector size is known.
This commit is contained in:
Pietro Albini 2018-11-01 11:55:28 +01:00 committed by kennytm
commit 133ba2d063
No known key found for this signature in database
GPG key ID: FEF6C8051D0E013C
2 changed files with 3 additions and 1 deletions

View file

@ -387,6 +387,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
add_derived_markers(&mut self.cx, item.span(), &traits, item.clone());
let derives = derives.entry(invoc.expansion_data.mark).or_default();
derives.reserve(traits.len());
invocations.reserve(traits.len());
for path in &traits {
let mark = Mark::fresh(self.cx.current_expansion.mark);
derives.push(mark);

View file

@ -1384,7 +1384,7 @@ impl<'a> MethodDef<'a> {
// let __self2_vi = unsafe {
// std::intrinsics::discriminant_value(&arg2) } as i32;
// ```
let mut index_let_stmts: Vec<ast::Stmt> = Vec::new();
let mut index_let_stmts: Vec<ast::Stmt> = Vec::with_capacity(vi_idents.len() + 1);
// We also build an expression which checks whether all discriminants are equal
// discriminant_test = __self0_vi == __self1_vi && __self0_vi == __self2_vi && ...