Skip to content

Commit 133ba2d

Browse files
pietroalbinikennytm
authored andcommitted
Rollup merge of rust-lang#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.
2 parents 912f00c + f4c03fd commit 133ba2d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/libsyntax/ext/expand.rs

+2
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
387387
add_derived_markers(&mut self.cx, item.span(), &traits, item.clone());
388388
let derives = derives.entry(invoc.expansion_data.mark).or_default();
389389

390+
derives.reserve(traits.len());
391+
invocations.reserve(traits.len());
390392
for path in &traits {
391393
let mark = Mark::fresh(self.cx.current_expansion.mark);
392394
derives.push(mark);

src/libsyntax_ext/deriving/generic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ impl<'a> MethodDef<'a> {
13841384
// let __self2_vi = unsafe {
13851385
// std::intrinsics::discriminant_value(&arg2) } as i32;
13861386
// ```
1387-
let mut index_let_stmts: Vec<ast::Stmt> = Vec::new();
1387+
let mut index_let_stmts: Vec<ast::Stmt> = Vec::with_capacity(vi_idents.len() + 1);
13881388

13891389
// We also build an expression which checks whether all discriminants are equal
13901390
// discriminant_test = __self0_vi == __self1_vi && __self0_vi == __self2_vi && ...

0 commit comments

Comments
 (0)