summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-10-14 08:24:17 -0700
committerAlex Crichton <alex@alexcrichton.com>2013-10-18 09:20:08 -0700
commit273784e9bfa006c2651c7890d8e5fb3564b95ec4 (patch)
treeaef326fcb9cf0e98a40c59cfbfab676e67c73f99 /src/libsyntax/ext
parent40180cdbea708307ca66dc6debddbd5ecc1ea41c (diff)
downloadrust-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/ext')
-rw-r--r--src/libsyntax/ext/source_util.rs19
1 files changed, 11 insertions, 8 deletions
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))
+        }
     }
 }