about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2016-10-20 13:53:27 +1100
committerNicholas Nethercote <nnethercote@mozilla.com>2016-10-20 15:08:01 +1100
commit94771a177ba133bfadd0ffba55d82e7e3989ea06 (patch)
tree56b3ae8d4647fed619da68f73369cc40de6388b1
parentfeefe77125b3b68d12f08ea5dd606d9542e509e0 (diff)
downloadrust-94771a177ba133bfadd0ffba55d82e7e3989ea06.tar.gz
rust-94771a177ba133bfadd0ffba55d82e7e3989ea06.zip
Use fast decompression in `deflate_bytes`.
This commit changes the parameters of `deflate` to do faster,
lower-quality compression. For the compression of LLVM bytecode -- which
is the main use of `deflate_bytes` -- it makes compression almost twice
as fast while the size of the compressed files is only ~2% worse.
-rw-r--r--src/libflate/lib.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs
index 89df931da02..3c608ef9c92 100644
--- a/src/libflate/lib.rs
+++ b/src/libflate/lib.rs
@@ -94,11 +94,14 @@ extern "C" {
                                     -> *mut c_void;
 }
 
-const LZ_NORM: c_int = 0x80;  // LZ with 128 probes, "normal"
+const LZ_FAST: c_int = 0x01;  // LZ with 1 probe, "fast"
+const TDEFL_GREEDY_PARSING_FLAG: c_int = 0x04000; // fast greedy parsing instead of lazy parsing
 
-/// Compress a buffer without writing any sort of header on the output.
+/// Compress a buffer without writing any sort of header on the output. Fast
+/// compression is used because it is almost twice as fast as default
+/// compression and the compression ratio is only marginally worse.
 pub fn deflate_bytes(bytes: &[u8]) -> Bytes {
-    let flags = LZ_NORM;
+    let flags = LZ_FAST | TDEFL_GREEDY_PARSING_FLAG;
     unsafe {
         let mut outsz: size_t = 0;
         let res = tdefl_compress_mem_to_heap(bytes.as_ptr() as *const _,