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
2 changed files with 3 additions and 1 deletions
+2
View File
@@ -387,6 +387,8 @@ fn expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragment {
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);
+1 -1
View File
@@ -1384,7 +1384,7 @@ fn build_enum_match_tuple<'b>(&self,
// 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 && ...