diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2016-10-14 09:44:42 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2016-10-14 16:38:12 +1100 |
| commit | 029dceedb9719ae5dbdbf2c033c920017e3d786e (patch) | |
| tree | 2e8d8a6503c5bf900944c64099b6f23bd199c956 /src/libsyntax/ext/quote.rs | |
| parent | d34318dd538bf4c9175e4138b3e4188ea8211620 (diff) | |
| download | rust-029dceedb9719ae5dbdbf2c033c920017e3d786e.tar.gz rust-029dceedb9719ae5dbdbf2c033c920017e3d786e.zip | |
Avoid many CrateConfig clones.
This commit changes `ExtCtx::cfg()` so it returns a `CrateConfig` reference instead of a clone. As a result, it also changes all of the `cfg()` callsites to explicitly clone... except one, because the commit also changes `macro_parser::parse()` to take `&CrateConfig`. This is good, because that function can be hot, and `CrateConfig` is expensive to clone. This change almost halves the number of heap allocations done by rustc for `html5ever` in rustc-benchmarks suite, which makes compilation 1.20x faster.
Diffstat (limited to 'src/libsyntax/ext/quote.rs')
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index b70e270df54..7f002d28166 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -331,7 +331,7 @@ pub mod rt { panictry!(parse::parse_item_from_source_str( "<quote expansion>".to_string(), s, - self.cfg(), + self.cfg().clone(), self.parse_sess())).expect("parse error") } @@ -339,7 +339,7 @@ pub mod rt { panictry!(parse::parse_stmt_from_source_str( "<quote expansion>".to_string(), s, - self.cfg(), + self.cfg().clone(), self.parse_sess())).expect("parse error") } @@ -347,7 +347,7 @@ pub mod rt { panictry!(parse::parse_expr_from_source_str( "<quote expansion>".to_string(), s, - self.cfg(), + self.cfg().clone(), self.parse_sess())) } @@ -355,7 +355,7 @@ pub mod rt { panictry!(parse::parse_tts_from_source_str( "<quote expansion>".to_string(), s, - self.cfg(), + self.cfg().clone(), self.parse_sess())) } } @@ -924,6 +924,10 @@ fn expand_parse_call(cx: &ExtCtxt, sp, cx.expr_ident(sp, id_ext("ext_cx")), id_ext("cfg"), Vec::new()); + let cfg_clone_call = || cx.expr_method_call( + sp, cfg_call(), + id_ext("clone"), Vec::new()); + let parse_sess_call = || cx.expr_method_call( sp, cx.expr_ident(sp, id_ext("ext_cx")), id_ext("parse_sess"), Vec::new()); @@ -931,7 +935,7 @@ fn expand_parse_call(cx: &ExtCtxt, let new_parser_call = cx.expr_call(sp, cx.expr_ident(sp, id_ext("new_parser_from_tts")), - vec!(parse_sess_call(), cfg_call(), tts_expr)); + vec!(parse_sess_call(), cfg_clone_call(), tts_expr)); let path = vec![id_ext("syntax"), id_ext("ext"), id_ext("quote"), id_ext(parse_method)]; let mut args = vec![cx.expr_mut_addr_of(sp, new_parser_call)]; |
