Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to rle_decode_fast crate #38

Merged
merged 7 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ codecov = {repository = "sile/libflate"}
adler32 = "1"
byteorder = "1"
crc32fast = "1"
rle-decode-fast = "1.0.0"
take_mut = "0.2.2"

[dev-dependencies]
Expand Down
16 changes: 2 additions & 14 deletions src/deflate/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use byteorder::ReadBytesExt;
use std::cmp;
use std::io;
use std::io::Read;
use rle_decode_fast::rle_decode;

use super::symbol;
use bit;
use lz77;
use util;

/// DEFLATE decoder.
#[derive(Debug)]
Expand Down Expand Up @@ -116,19 +116,7 @@ where
distance
));
}
let old_len = self.buffer.len();
self.buffer.reserve(length as usize);
unsafe {
self.buffer.set_len(old_len + length as usize);
let start = old_len - distance as usize;
let ptr = self.buffer.as_mut_ptr();
util::ptr_copy(
ptr.add(start),
ptr.add(old_len),
length as usize,
length > distance,
);
}
rle_decode(&mut self.buffer, usize::from(distance), usize::from(length));
}
symbol::Symbol::EndOfBlock => {
break;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
extern crate adler32;
extern crate byteorder;
extern crate crc32fast;
extern crate rle_decode_fast;
extern crate take_mut;

pub use finish::Finish;
Expand Down
17 changes: 2 additions & 15 deletions src/non_blocking/deflate/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use byteorder::ReadBytesExt;
use std::cmp;
use std::io;
use std::io::Read;
use rle_decode_fast::rle_decode;

use deflate::symbol::{self, HuffmanCodec};
use lz77;
use non_blocking::transaction::TransactionalBitReader;
use util;

/// DEFLATE decoder which supports non-blocking I/O.
#[derive(Debug)]
pub struct Decoder<R> {
Expand Down Expand Up @@ -210,19 +209,7 @@ impl BlockDecoder {
distance
));
}
let old_len = self.buffer.len();
self.buffer.reserve(length as usize);
unsafe {
self.buffer.set_len(old_len + length as usize);
let start = old_len - distance as usize;
let ptr = self.buffer.as_mut_ptr();
util::ptr_copy(
ptr.add(start),
ptr.add(old_len),
length as usize,
length > distance,
);
}
rle_decode(&mut self.buffer, usize::from(distance), usize::from(length));
}
symbol::Symbol::EndOfBlock => {
self.eob = true;
Expand Down
12 changes: 0 additions & 12 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
#[cfg(test)]
use std::io::{self, Read};
use std::ptr;

#[inline]
pub unsafe fn ptr_copy(src: *const u8, dst: *mut u8, count: usize, is_overlapping: bool) {
if !is_overlapping {
ptr::copy_nonoverlapping(src, dst, count);
} else {
for i in 0..count {
ptr::copy_nonoverlapping(src.add(i), dst.add(i), 1);
}
}
}

#[cfg(test)]
pub struct WouldBlockReader<R> {
Expand Down