sile / libflate

A Rust implementation of DEFLATE algorithm and related formats (ZLIB, GZIP)
https://docs.rs/libflate
MIT License
178 stars 35 forks source link

Address part of #31 #34

Closed Shnatsel closed 5 years ago

Shnatsel commented 5 years ago

Fixes one occurrence of unsoundness described in #31

This change actually makes decoding 5% faster - as measured with hyperfine:

hyperfine -m 25 --warmup=3 'target/release/examples/flate -i enwiki-latest-all-titles-in-ns0.gz -o /dev/null gzip-decode'

On my machine the time goes down from 2.250s to 2.150s

Tests still pass.

codecov-io commented 5 years ago

Codecov Report

Merging #34 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #34   +/-   ##
=======================================
  Coverage   91.46%   91.46%           
=======================================
  Files          14       14           
  Lines        1301     1301           
=======================================
  Hits         1190     1190           
  Misses        111      111

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 691454e...5a7bcd1. Read the comment docs.

Stargateur commented 5 years ago

This could be write:

self.bit_reader
    .as_inner_mut()
    .take(len.into())
    .read_to_end(&mut self.buffer)
    .and_then(|used| {
        if used != len.into() {
            Err(io::Error::new(
                io::ErrorKind::UnexpectedEof,
                "Say something here",
            ))
        } else {
            Ok(())
        }
    })

This should be both safe and fast. I do not really follow you about your claim your PR is more fast, just with one test on your machine.

Shnatsel commented 5 years ago

@Stargateur nice! Care to open a PR for that?

Stargateur commented 5 years ago

@Shnatsel Done