Skip to content

Commit 041d8e8

Browse files
committed
Allow metadata to be not compressed
1 parent 9feaf1d commit 041d8e8

File tree

7 files changed

+51
-12
lines changed

7 files changed

+51
-12
lines changed

Makefile.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ else
107107
CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
108108
endif
109109

110+
ifndef CFG_ENABLE_COMPRESS_METADATA
111+
# XXX: After snapshots extend this to all stages
112+
RUSTFLAGS_STAGE1 += --no-compress-metadata
113+
RUSTFLAGS_STAGE2 += --no-compress-metadata
114+
endif
115+
110116
ifdef SAVE_TEMPS
111117
CFG_RUSTC_FLAGS += --save-temps
112118
endif

configure

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,9 @@ opt mingw-cross 0 "cross-compile for win32 using mingw"
381381
opt clang 0 "prefer clang to gcc for building the runtime"
382382
opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
383383
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
384-
opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)"
384+
opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched
385+
kernels)"
386+
opt compress-metadata 0 "compress crate metadata"
385387
valopt prefix "/usr/local" "set installation prefix"
386388
valopt local-rust-root "/usr/local" "set prefix for local rust binary"
387389
valopt llvm-root "" "set LLVM root"

src/librustc/driver/driver.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ pub fn build_session_options(binary: @str,
718718
let android_cross_path = getopts::opt_maybe_str(
719719
matches, "android-cross-path");
720720

721+
let no_compress_metadata = opt_present(matches, "no-compress-metadata");
722+
721723
let custom_passes = match getopts::opt_maybe_str(matches, "passes") {
722724
None => ~[],
723725
Some(s) => {
@@ -752,7 +754,8 @@ pub fn build_session_options(binary: @str,
752754
parse_only: parse_only,
753755
no_trans: no_trans,
754756
debugging_opts: debugging_opts,
755-
android_cross_path: android_cross_path
757+
android_cross_path: android_cross_path,
758+
no_compress_metadata: no_compress_metadata
756759
};
757760
return sopts;
758761
}
@@ -870,6 +873,8 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
870873
for details)", "FEATURE"),
871874
optopt("", "android-cross-path",
872875
"The path to the Android NDK", "PATH"),
876+
optflag("", "no-compress-metadata",
877+
"Do not compress crate metadata (make builds a little faster)"),
873878
optflagopt("W", "warn",
874879
"Set lint warnings", "OPT"),
875880
optmulti("A", "allow",

src/librustc/driver/session.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ pub struct options {
166166
no_trans: bool,
167167
debugging_opts: uint,
168168
android_cross_path: Option<~str>,
169+
no_compress_metadata: bool
169170
}
170171

171172
pub struct crate_metadata {
@@ -350,6 +351,7 @@ pub fn basic_options() -> @options {
350351
no_trans: false,
351352
debugging_opts: 0u,
352353
android_cross_path: None,
354+
no_compress_metadata: false
353355
}
354356
}
355357

src/librustc/metadata/encoder.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub struct EncodeParams<'self> {
6464
cstore: @mut cstore::CStore,
6565
encode_inlined_item: encode_inlined_item<'self>,
6666
reachable: @mut HashSet<ast::NodeId>,
67+
compress: bool
6768
}
6869

6970
struct Stats {
@@ -1567,7 +1568,7 @@ pub static metadata_encoding_version : &'static [u8] =
15671568
0x75, //'u' as u8,
15681569
0x73, //'s' as u8,
15691570
0x74, //'t' as u8,
1570-
0, 0, 0, 1 ];
1571+
0, 0, 0, 2 ];
15711572

15721573
pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
15731574
let wr = @io::BytesWriter::new();
@@ -1594,6 +1595,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
15941595
encode_inlined_item,
15951596
link_meta,
15961597
reachable,
1598+
compress,
15971599
_
15981600
} = parms;
15991601
let type_abbrevs = @mut HashMap::new();
@@ -1679,9 +1681,17 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
16791681
wr.write(&[0u8, 0u8, 0u8, 0u8]);
16801682

16811683
let writer_bytes: &mut ~[u8] = wr.bytes;
1682-
1683-
metadata_encoding_version.to_owned() +
1684-
flate::deflate_bytes(*writer_bytes)
1684+
let compression_flag = if compress { [1u8] } else { [0u8] };
1685+
1686+
if compress {
1687+
metadata_encoding_version.to_owned() +
1688+
compression_flag.to_owned() +
1689+
flate::deflate_bytes(*writer_bytes)
1690+
} else {
1691+
metadata_encoding_version.to_owned() +
1692+
compression_flag.to_owned() +
1693+
*writer_bytes
1694+
}
16851695
}
16861696

16871697
// Get the encoded string for a type

src/librustc/metadata/loader.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,26 @@ fn get_metadata_section(os: os,
228228
}
229229
if !version_ok { return None; }
230230

231-
let cvbuf1 = ptr::offset(cvbuf, vlen as int);
232-
debug!("inflating %u bytes of compressed metadata",
233-
csz - vlen);
234-
do vec::raw::buf_as_slice(cvbuf1, csz-vlen) |bytes| {
235-
let inflated = flate::inflate_bytes(bytes);
236-
found = Some(@(inflated));
231+
assert!(csz >= vlen + 1);
232+
233+
let must_decompress = *ptr::offset(cvbuf, vlen as int) == 1;
234+
let cvbuf1 = ptr::offset(cvbuf, vlen as int + 1);
235+
236+
do vec::raw::buf_as_slice(cvbuf1, csz-vlen-1) |bytes| {
237+
if must_decompress {
238+
debug!("inflating %u bytes of compressed metadata",
239+
csz - vlen);
240+
let inflated = flate::inflate_bytes(bytes);
241+
found = Some(@(inflated));
242+
} else {
243+
// Copy the byte vector as fast as possible
244+
let mut buf = vec::with_capacity(bytes.len());
245+
vec::raw::set_len(&mut buf, bytes.len());
246+
vec::raw::copy_memory(buf, bytes, bytes.len());
247+
found = Some(@buf)
248+
}
237249
}
250+
238251
if found != None {
239252
return found;
240253
}

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,7 @@ pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::encode_
29072907
cstore: cx.sess.cstore,
29082908
encode_inlined_item: ie,
29092909
reachable: cx.reachable,
2910+
compress: !cx.sess.opts.no_compress_metadata
29102911
}
29112912
}
29122913

0 commit comments

Comments
 (0)