From 273784e9bfa006c2651c7890d8e5fb3564b95ec4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 14 Oct 2013 08:24:17 -0700 Subject: Optimize include_bin! for large inputs Previously an ExprLit was created *per byte* causing a huge increase in memory bloat. This adds a new `lit_binary` to contain a literal of binary data, which is currently only used by the include_bin! syntax extension. This massively speeds up compilation times of the shootout-k-nucleotide-pipes test before: time: 469s memory: 6GB assertion failure in LLVM (section too large) after: time: 2.50s memory: 124MB Closes #2598 --- src/libsyntax/ext/source_util.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 1c13beb790d..dcfeb99365a 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -101,16 +101,19 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) } pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) - -> base::MacResult { + -> base::MacResult +{ + use std::at_vec; + let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); match io::read_whole_file(&res_rel_file(cx, sp, &Path::new(file))) { - result::Ok(src) => { - let u8_exprs: ~[@ast::Expr] = src.iter().map(|char| cx.expr_u8(sp, *char)).collect(); - base::MRExpr(cx.expr_vec(sp, u8_exprs)) - } - result::Err(ref e) => { - cx.parse_sess().span_diagnostic.handler().fatal((*e)) - } + result::Ok(src) => { + let v = at_vec::to_managed_move(src); + base::MRExpr(cx.expr_lit(sp, ast::lit_binary(v))) + } + result::Err(ref e) => { + cx.parse_sess().span_diagnostic.handler().fatal((*e)) + } } } -- cgit 1.4.1-3-g733a5