Compress metadata section. Seems a minor speed win, major space win.
This commit is contained in:
parent
31bbcf0267
commit
b769e29680
@ -235,6 +235,11 @@ included:
|
||||
BSD-compatible licenses. See src/libuv/LICENSE for
|
||||
details.
|
||||
|
||||
* The src/rt/miniz.c file, carrying an implementation of
|
||||
RFC1950/RFC1951 DEFLATE, by Rich Geldreich
|
||||
<richgel99@gmail.com>. All uses of this file are
|
||||
permitted by the embedded "unlicense" notice
|
||||
(effectively: public domain with warranty disclaimer).
|
||||
|
||||
* LLVM and Clang. Code for this package is found in
|
||||
src/llvm.
|
||||
|
1
mk/rt.mk
1
mk/rt.mk
@ -65,6 +65,7 @@ RUNTIME_CS_$(1) := \
|
||||
rt/rust_util.cpp \
|
||||
rt/circular_buffer.cpp \
|
||||
rt/isaac/randport.cpp \
|
||||
rt/miniz.cpp \
|
||||
rt/rust_kernel.cpp \
|
||||
rt/rust_shape.cpp \
|
||||
rt/rust_abi.cpp \
|
||||
|
@ -121,6 +121,7 @@ ALL_CS := $(wildcard $(S)src/rt/*.cpp \
|
||||
$(S)srcrustllvm/*.cpp)
|
||||
ALL_CS := $(filter-out $(S)src/rt/bigint/bigint_ext.cpp \
|
||||
$(S)src/rt/bigint/bigint_int.cpp \
|
||||
$(S)src/rt/miniz.cpp \
|
||||
,$(ALL_CS))
|
||||
ALL_HS := $(wildcard $(S)src/rt/*.h \
|
||||
$(S)src/rt/*/*.h \
|
||||
|
@ -56,6 +56,7 @@ export cmp;
|
||||
export num;
|
||||
export path, path2;
|
||||
export managed;
|
||||
export flate;
|
||||
|
||||
// NDM seems to be necessary for resolve to work
|
||||
export option_iter;
|
||||
@ -265,6 +266,8 @@ mod unsafe;
|
||||
|
||||
mod managed;
|
||||
|
||||
mod flate;
|
||||
|
||||
// Modules supporting compiler-generated code
|
||||
// Exported but not part of the public interface
|
||||
|
||||
|
78
src/libcore/flate.rs
Normal file
78
src/libcore/flate.rs
Normal file
@ -0,0 +1,78 @@
|
||||
import libc::{c_void, size_t, c_int};
|
||||
|
||||
extern mod rustrt {
|
||||
|
||||
fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
|
||||
src_buf_len: size_t,
|
||||
pout_len: *size_t,
|
||||
flags: c_int) -> *c_void;
|
||||
|
||||
fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
|
||||
src_buf_len: size_t,
|
||||
pout_len: *size_t,
|
||||
flags: c_int) -> *c_void;
|
||||
}
|
||||
|
||||
const lz_none : c_int = 0x0; // Huffman-coding only.
|
||||
const lz_fast : c_int = 0x1; // LZ with only one probe
|
||||
const lz_norm : c_int = 0x80; // LZ with 128 probes, "normal"
|
||||
const lz_best : c_int = 0xfff; // LZ with 4095 probes, "best"
|
||||
|
||||
fn deflate_buf(buf: &[const u8]) -> ~[u8] {
|
||||
do vec::as_const_buf(buf) |b, len| {
|
||||
unsafe {
|
||||
let mut outsz : size_t = 0;
|
||||
let res =
|
||||
rustrt::tdefl_compress_mem_to_heap(b as *c_void,
|
||||
len as size_t,
|
||||
ptr::addr_of(outsz),
|
||||
lz_norm);
|
||||
assert res as int != 0;
|
||||
let out = vec::unsafe::from_buf(res as *u8,
|
||||
outsz as uint);
|
||||
libc::free(res);
|
||||
out
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn inflate_buf(buf: &[const u8]) -> ~[u8] {
|
||||
do vec::as_const_buf(buf) |b, len| {
|
||||
unsafe {
|
||||
let mut outsz : size_t = 0;
|
||||
let res =
|
||||
rustrt::tinfl_decompress_mem_to_heap(b as *c_void,
|
||||
len as size_t,
|
||||
ptr::addr_of(outsz),
|
||||
0);
|
||||
assert res as int != 0;
|
||||
let out = vec::unsafe::from_buf(res as *u8,
|
||||
outsz as uint);
|
||||
libc::free(res);
|
||||
out
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_flate_round_trip() {
|
||||
let r = rand::Rng();
|
||||
let mut words = ~[];
|
||||
for 20.times {
|
||||
vec::push(words, r.gen_bytes(r.gen_uint_range(1, 10)));
|
||||
}
|
||||
for 20.times {
|
||||
let mut in = ~[];
|
||||
for 2000.times {
|
||||
vec::push_all(in, r.choose(words));
|
||||
}
|
||||
debug!("de/inflate of %u bytes of random word-sequences",
|
||||
in.len());
|
||||
let cmp = flate::deflate_buf(in);
|
||||
let out = flate::inflate_buf(cmp);
|
||||
debug!("%u bytes deflated to %u (%.1f%% size)",
|
||||
in.len(), cmp.len(),
|
||||
100.0 * ((cmp.len() as float) / (in.len() as float)));
|
||||
assert(in == out);
|
||||
}
|
||||
}
|
1884
src/rt/miniz.cpp
Normal file
1884
src/rt/miniz.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -196,3 +196,5 @@ rust_task_local_data_atexit
|
||||
rust_task_ref
|
||||
rust_task_deref
|
||||
rust_call_tydesc_glue
|
||||
tdefl_compress_mem_to_heap
|
||||
tinfl_decompress_mem_to_heap
|
||||
|
@ -1164,7 +1164,7 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
||||
// Pad this, since something (LLVM, presumably) is cutting off the
|
||||
// remaining % 4 bytes.
|
||||
buf_w.write(&[0u8, 0u8, 0u8, 0u8]);
|
||||
io::mem_buffer_buf(buf)
|
||||
flate::deflate_buf(io::mem_buffer_buf(buf))
|
||||
}
|
||||
|
||||
// Get the encoded string for a type
|
||||
|
@ -187,7 +187,9 @@ fn get_metadata_section(os: os,
|
||||
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
|
||||
unsafe {
|
||||
let cvbuf: *u8 = unsafe::reinterpret_cast(cbuf);
|
||||
return Some(@vec::unsafe::from_buf(cvbuf, csz));
|
||||
let v = vec::unsafe::from_buf(cvbuf, csz);
|
||||
let inflated = flate::inflate_buf(v);
|
||||
return Some(@inflated);
|
||||
}
|
||||
}
|
||||
llvm::LLVMMoveToNextSection(si.llsi);
|
||||
|
Loading…
Reference in New Issue
Block a user