Allow metadata to be not compressed

This commit is contained in:
Brian Anderson 2013-08-22 13:46:47 -07:00
parent 9feaf1d023
commit 041d8e899f
7 changed files with 50 additions and 11 deletions

View File

@ -107,6 +107,12 @@ else
CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
endif
ifndef CFG_ENABLE_COMPRESS_METADATA
# XXX: After snapshots extend this to all stages
RUSTFLAGS_STAGE1 += --no-compress-metadata
RUSTFLAGS_STAGE2 += --no-compress-metadata
endif
ifdef SAVE_TEMPS
CFG_RUSTC_FLAGS += --save-temps
endif

4
configure vendored
View File

@ -381,7 +381,9 @@ opt mingw-cross 0 "cross-compile for win32 using mingw"
opt clang 0 "prefer clang to gcc for building the runtime"
opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)"
opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched
kernels)"
opt compress-metadata 0 "compress crate metadata"
valopt prefix "/usr/local" "set installation prefix"
valopt local-rust-root "/usr/local" "set prefix for local rust binary"
valopt llvm-root "" "set LLVM root"

View File

@ -718,6 +718,8 @@ pub fn build_session_options(binary: @str,
let android_cross_path = getopts::opt_maybe_str(
matches, "android-cross-path");
let no_compress_metadata = opt_present(matches, "no-compress-metadata");
let custom_passes = match getopts::opt_maybe_str(matches, "passes") {
None => ~[],
Some(s) => {
@ -752,7 +754,8 @@ pub fn build_session_options(binary: @str,
parse_only: parse_only,
no_trans: no_trans,
debugging_opts: debugging_opts,
android_cross_path: android_cross_path
android_cross_path: android_cross_path,
no_compress_metadata: no_compress_metadata
};
return sopts;
}
@ -870,6 +873,8 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
for details)", "FEATURE"),
optopt("", "android-cross-path",
"The path to the Android NDK", "PATH"),
optflag("", "no-compress-metadata",
"Do not compress crate metadata (make builds a little faster)"),
optflagopt("W", "warn",
"Set lint warnings", "OPT"),
optmulti("A", "allow",

View File

@ -166,6 +166,7 @@ pub struct options {
no_trans: bool,
debugging_opts: uint,
android_cross_path: Option<~str>,
no_compress_metadata: bool
}
pub struct crate_metadata {
@ -350,6 +351,7 @@ pub fn basic_options() -> @options {
no_trans: false,
debugging_opts: 0u,
android_cross_path: None,
no_compress_metadata: false
}
}

View File

@ -64,6 +64,7 @@ pub struct EncodeParams<'self> {
cstore: @mut cstore::CStore,
encode_inlined_item: encode_inlined_item<'self>,
reachable: @mut HashSet<ast::NodeId>,
compress: bool
}
struct Stats {
@ -1567,7 +1568,7 @@ pub static metadata_encoding_version : &'static [u8] =
0x75, //'u' as u8,
0x73, //'s' as u8,
0x74, //'t' as u8,
0, 0, 0, 1 ];
0, 0, 0, 2 ];
pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
let wr = @io::BytesWriter::new();
@ -1594,6 +1595,7 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
encode_inlined_item,
link_meta,
reachable,
compress,
_
} = parms;
let type_abbrevs = @mut HashMap::new();
@ -1679,9 +1681,17 @@ pub fn encode_metadata(parms: EncodeParams, crate: &Crate) -> ~[u8] {
wr.write(&[0u8, 0u8, 0u8, 0u8]);
let writer_bytes: &mut ~[u8] = wr.bytes;
let compression_flag = if compress { [1u8] } else { [0u8] };
metadata_encoding_version.to_owned() +
flate::deflate_bytes(*writer_bytes)
if compress {
metadata_encoding_version.to_owned() +
compression_flag.to_owned() +
flate::deflate_bytes(*writer_bytes)
} else {
metadata_encoding_version.to_owned() +
compression_flag.to_owned() +
*writer_bytes
}
}
// Get the encoded string for a type

View File

@ -228,13 +228,26 @@ fn get_metadata_section(os: os,
}
if !version_ok { return None; }
let cvbuf1 = ptr::offset(cvbuf, vlen as int);
debug!("inflating %u bytes of compressed metadata",
csz - vlen);
do vec::raw::buf_as_slice(cvbuf1, csz-vlen) |bytes| {
let inflated = flate::inflate_bytes(bytes);
found = Some(@(inflated));
assert!(csz >= vlen + 1);
let must_decompress = *ptr::offset(cvbuf, vlen as int) == 1;
let cvbuf1 = ptr::offset(cvbuf, vlen as int + 1);
do vec::raw::buf_as_slice(cvbuf1, csz-vlen-1) |bytes| {
if must_decompress {
debug!("inflating %u bytes of compressed metadata",
csz - vlen);
let inflated = flate::inflate_bytes(bytes);
found = Some(@(inflated));
} else {
// Copy the byte vector as fast as possible
let mut buf = vec::with_capacity(bytes.len());
vec::raw::set_len(&mut buf, bytes.len());
vec::raw::copy_memory(buf, bytes, bytes.len());
found = Some(@buf)
}
}
if found != None {
return found;
}

View File

@ -2907,6 +2907,7 @@ pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::encode_
cstore: cx.sess.cstore,
encode_inlined_item: ie,
reachable: cx.reachable,
compress: !cx.sess.opts.no_compress_metadata
}
}