diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-10-14 08:24:17 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-10-18 09:20:08 -0700 |
| commit | 273784e9bfa006c2651c7890d8e5fb3564b95ec4 (patch) | |
| tree | aef326fcb9cf0e98a40c59cfbfab676e67c73f99 /src/libsyntax | |
| parent | 40180cdbea708307ca66dc6debddbd5ecc1ea41c (diff) | |
| download | rust-273784e9bfa006c2651c7890d8e5fb3564b95ec4.tar.gz rust-273784e9bfa006c2651c7890d8e5fb3564b95ec4.zip | |
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
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 8 |
3 files changed, 20 insertions, 8 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 08e1390a981..34b359ef3db 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -691,6 +691,7 @@ pub type lit = Spanned<lit_>; #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum lit_ { lit_str(@str, StrStyle), + lit_binary(@[u8]), lit_char(u32), lit_int(i64, int_ty), lit_uint(u64, uint_ty), 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)) + } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 607eb81102f..0d442dca9b6 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2092,6 +2092,14 @@ pub fn print_literal(s: @ps, lit: &ast::lit) { ast::lit_bool(val) => { if val { word(s.s, "true"); } else { word(s.s, "false"); } } + ast::lit_binary(arr) => { + ibox(s, indent_unit); + word(s.s, "["); + commasep_cmnt(s, inconsistent, arr, |s, u| word(s.s, format!("{}", *u)), + |_| lit.span); + word(s.s, "]"); + end(s); + } } } |
