diff options
| author | Pietro Albini <pietro@pietroalbini.org> | 2018-11-01 11:55:28 +0100 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-11-01 22:52:15 +0800 |
| commit | 133ba2d063af3a078dff30ff4df3dd864082fcb5 (patch) | |
| tree | 9b496b41355d5c34b2bd2a986eb9e189c2bcc97e /src | |
| parent | 912f00c187fbe6293a71e2c3c46e14e5d5f7385c (diff) | |
| parent | f4c03fd8473c2b5a254789abcb712c90b558f92d (diff) | |
| download | rust-133ba2d063af3a078dff30ff4df3dd864082fcb5.tar.gz rust-133ba2d063af3a078dff30ff4df3dd864082fcb5.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ce326b728df..41ed90fb94e 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -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); diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 002ecce58e6..dd90ef06c39 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -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 && ... |
