Skip to content

Commit

Permalink
remove dictionary access from catable brotli files
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrh committed Sep 26, 2018
1 parent 7fa9060 commit 25c1ad7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
42 changes: 21 additions & 21 deletions src/enc/backward_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub trait AnyHasher {
fn StoreLookahead(&self) -> usize;
fn PrepareDistanceCache(&self, distance_cache: &mut [i32]);
fn FindLongestMatch(&mut self,
dictionary: &BrotliDictionary,
dictionary: Option<&BrotliDictionary>,
dictionary_hash: &[u16],
data: &[u8],
ring_buffer_mask: usize,
Expand Down Expand Up @@ -268,7 +268,7 @@ impl<T: SliceWrapperMut<u32> + SliceWrapper<u32> + BasicHashComputer> AnyHasher
}

fn FindLongestMatch(&mut self,
dictionary: &BrotliDictionary,
dictionary: Option<&BrotliDictionary>,
dictionary_hash: &[u16],
data: &[u8],
ring_buffer_mask: usize,
Expand Down Expand Up @@ -384,8 +384,8 @@ impl<T: SliceWrapperMut<u32> + SliceWrapper<u32> + BasicHashComputer> AnyHasher
}
}
}
if self.buckets_.USE_DICTIONARY() != 0 && (is_match_found == 0) {
is_match_found = SearchInStaticDictionary(dictionary,
if dictionary.is_some() && self.buckets_.USE_DICTIONARY() != 0 && (is_match_found == 0) {
is_match_found = SearchInStaticDictionary(dictionary.unwrap(),
dictionary_hash,
self,
&data[(cur_ix_masked as (usize))..],
Expand Down Expand Up @@ -648,7 +648,7 @@ impl<Alloc: alloc::Allocator<u16> + alloc::Allocator<u32>> AnyHasher for H9<Allo
adv_prepare_distance_cache(distance_cache, num_distances);
}
fn FindLongestMatch(&mut self,
dictionary: &BrotliDictionary,
dictionary: Option<&BrotliDictionary>,
dictionary_hash: &[u16],
data: &[u8],
ring_buffer_mask: usize,
Expand Down Expand Up @@ -749,9 +749,9 @@ impl<Alloc: alloc::Allocator<u16> + alloc::Allocator<u32>> AnyHasher for H9<Allo
bucket[*self_num_key as usize & H9_BLOCK_MASK] = cur_ix as u32;
*self_num_key = self_num_key.wrapping_add(1);
}
if (is_match_found == 0) {
if is_match_found == 0 && dictionary.is_some() {
let (_, cur_data) = data.split_at(cur_ix_masked as usize);
is_match_found = SearchInStaticDictionary(dictionary,
is_match_found = SearchInStaticDictionary(dictionary.unwrap(),
dictionary_hash,
self,
cur_data,
Expand Down Expand Up @@ -947,7 +947,7 @@ impl<Specialization: AdvHashSpecialization, Alloc: alloc::Allocator<u16> + alloc
}

fn FindLongestMatch(&mut self,
dictionary: &BrotliDictionary,
dictionary: Option<&BrotliDictionary>,
dictionary_hash: &[u16],
data: &[u8],
ring_buffer_mask: usize,
Expand Down Expand Up @@ -1080,9 +1080,9 @@ impl<Specialization: AdvHashSpecialization, Alloc: alloc::Allocator<u16> + alloc
*_lhs = (*_lhs as (i32) + _rhs) as (u16);
}
}
if is_match_found == 0 {
if is_match_found == 0 && dictionary.is_some() {
let (_, cur_data) = data.split_at(cur_ix_masked as usize);
is_match_found = SearchInStaticDictionary(dictionary,
is_match_found = SearchInStaticDictionary(dictionary.unwrap(),
dictionary_hash,
self,
cur_data,
Expand Down Expand Up @@ -1357,7 +1357,7 @@ impl<Alloc: alloc::Allocator<u16> + alloc::Allocator<u32>> AnyHasher
ringbuffer_mask);
}
fn FindLongestMatch(&mut self,
dictionary: &BrotliDictionary,
dictionary: Option<&BrotliDictionary>,
dictionary_hash: &[u16],
data: &[u8],
ring_buffer_mask: usize,
Expand Down Expand Up @@ -1451,7 +1451,7 @@ impl<Alloc: alloc::Allocator<u16> + alloc::Allocator<u32>> Default
},
})
*/
fn CreateBackwardReferences<AH: AnyHasher>(dictionary: &BrotliDictionary,
fn CreateBackwardReferences<AH: AnyHasher>(dictionary: Option<&BrotliDictionary>,
dictionary_hash: &[u16],
num_bytes: usize,
mut position: usize,
Expand Down Expand Up @@ -1642,7 +1642,7 @@ pub fn BrotliCreateBackwardReferences<Alloc: alloc::Allocator<u16> + alloc::Allo
&mut UnionHasher::H10(ref mut hasher) => {
if params.quality >= 11 {
super::backward_references_hq::BrotliCreateHqZopfliBackwardReferences(
alloc, dictionary,
alloc, if params.catable {None} else {Some(dictionary)},
num_bytes,
position,
ringbuffer,
Expand All @@ -1657,7 +1657,7 @@ pub fn BrotliCreateBackwardReferences<Alloc: alloc::Allocator<u16> + alloc::Allo
} else {
super::backward_references_hq::BrotliCreateZopfliBackwardReferences(
alloc,
dictionary,
if params.catable {None} else {Some(dictionary)},
num_bytes,
position,
ringbuffer,
Expand All @@ -1672,7 +1672,7 @@ pub fn BrotliCreateBackwardReferences<Alloc: alloc::Allocator<u16> + alloc::Allo
}
}
&mut UnionHasher::H2(ref mut hasher) => {
CreateBackwardReferences(dictionary,
CreateBackwardReferences(if params.catable {None} else {Some(dictionary)},
&kStaticDictionaryHash[..],
num_bytes,
position,
Expand All @@ -1687,7 +1687,7 @@ pub fn BrotliCreateBackwardReferences<Alloc: alloc::Allocator<u16> + alloc::Allo
num_literals)
}
&mut UnionHasher::H3(ref mut hasher) => {
CreateBackwardReferences(dictionary,
CreateBackwardReferences(if params.catable {None} else {Some(dictionary)},
&kStaticDictionaryHash[..],
num_bytes,
position,
Expand All @@ -1702,7 +1702,7 @@ pub fn BrotliCreateBackwardReferences<Alloc: alloc::Allocator<u16> + alloc::Allo
num_literals)
}
&mut UnionHasher::H4(ref mut hasher) => {
CreateBackwardReferences(dictionary,
CreateBackwardReferences(if params.catable {None} else {Some(dictionary)},
&kStaticDictionaryHash[..],
num_bytes,
position,
Expand All @@ -1717,7 +1717,7 @@ pub fn BrotliCreateBackwardReferences<Alloc: alloc::Allocator<u16> + alloc::Allo
num_literals)
}
&mut UnionHasher::H5(ref mut hasher) => {
CreateBackwardReferences(dictionary,
CreateBackwardReferences(if params.catable {None} else {Some(dictionary)},
&kStaticDictionaryHash[..],
num_bytes,
position,
Expand All @@ -1732,7 +1732,7 @@ pub fn BrotliCreateBackwardReferences<Alloc: alloc::Allocator<u16> + alloc::Allo
num_literals)
}
&mut UnionHasher::H6(ref mut hasher) => {
CreateBackwardReferences(dictionary,
CreateBackwardReferences(if params.catable {None} else {Some(dictionary)},
&kStaticDictionaryHash[..],
num_bytes,
position,
Expand All @@ -1747,7 +1747,7 @@ pub fn BrotliCreateBackwardReferences<Alloc: alloc::Allocator<u16> + alloc::Allo
num_literals)
}
&mut UnionHasher::H9(ref mut hasher) => {
CreateBackwardReferences(dictionary,
CreateBackwardReferences(if params.catable {None} else {Some(dictionary)},
&kStaticDictionaryHash[..],
num_bytes,
position,
Expand All @@ -1762,7 +1762,7 @@ pub fn BrotliCreateBackwardReferences<Alloc: alloc::Allocator<u16> + alloc::Allo
num_literals)
}
&mut UnionHasher::H54(ref mut hasher) => {
CreateBackwardReferences(dictionary,
CreateBackwardReferences(if params.catable {None} else {Some(dictionary)},
&kStaticDictionaryHash[..],
num_bytes,
position,
Expand Down
17 changes: 9 additions & 8 deletions src/enc/backward_references_hq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ pub fn StitchToPreviousBlockH10<AllocU32:Allocator<u32>,
}
fn FindAllMatchesH10<AllocU32:Allocator<u32>, Buckets: Allocable<u32, AllocU32>+SliceWrapperMut<u32>+SliceWrapper<u32>, Params:H10Params>(
handle : &mut H10<AllocU32, Buckets, Params>,
dictionary : & BrotliDictionary,
dictionary : Option<&BrotliDictionary>,
data : & [u8],
ring_buffer_mask : usize,
cur_ix : usize,
Expand Down Expand Up @@ -490,13 +490,14 @@ fn FindAllMatchesH10<AllocU32:Allocator<u32>, Buckets: Allocable<u32, AllocU32>+
4usize,
best_len.wrapping_add(1usize)
);
if BrotliFindAllStaticDictionaryMatches(
&dictionary,
if dictionary.is_some() && BrotliFindAllStaticDictionaryMatches(
dictionary.unwrap(),
&data[(cur_ix_masked as (usize))..],
minlen,
max_length,
&mut dict_matches[..]
) != 0 {
&mut dict_matches[..],
) != 0 {
assert_eq!(params.catable, false);
let maxlen
: usize
= brotli_min_size_t(37usize,max_length);
Expand Down Expand Up @@ -1171,7 +1172,7 @@ pub fn BrotliZopfliComputeShortestPath<AllocU32:Allocator<u32>,
Params:H10Params,
AllocF:Allocator<floatX>>(
m : &mut AllocF,
dictionary: &BrotliDictionary,
dictionary: Option<&BrotliDictionary>,
num_bytes : usize,
position : usize,
ringbuffer : & [u8],
Expand Down Expand Up @@ -1332,7 +1333,7 @@ pub fn BrotliCreateZopfliBackwardReferences<Alloc:Allocator<u32> + Allocator<flo
Buckets: Allocable<u32, Alloc>+SliceWrapperMut<u32>+SliceWrapper<u32>,
Params:H10Params>(
alloc : &mut Alloc,
dictionary: &BrotliDictionary,
dictionary: Option<&BrotliDictionary>,
num_bytes : usize,
position : usize,
ringbuffer : & [u8],
Expand Down Expand Up @@ -1682,7 +1683,7 @@ pub fn BrotliCreateHqZopfliBackwardReferences<Alloc:Allocator<u32> + Allocator<u
Buckets:Allocable<u32, Alloc>+SliceWrapperMut<u32>+SliceWrapper<u32>,
Params: H10Params>(
alloc : &mut Alloc,
dictionary: &BrotliDictionary,
dictionary: Option<&BrotliDictionary>,
num_bytes : usize,
position : usize,
ringbuffer : & [u8],
Expand Down
2 changes: 1 addition & 1 deletion src/enc/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ pub fn BrotliEncoderSetCustomDictionary<Alloc: BrotliAlloc>
if EnsureInitialized(s) == 0 {
return;
}
if dict_size == 0usize || (*s).params.quality == 0i32 || (*s).params.quality == 1i32 {
if dict_size == 0usize || (*s).params.quality == 0i32 || (*s).params.quality == 1i32 || s.params.catable {
return;
}
if size > max_dict_size {
Expand Down
2 changes: 1 addition & 1 deletion src/enc/hash_to_binary_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl<AllocU32: Allocator<u32>,
}

fn FindLongestMatch(&mut self,
_dictionary: &BrotliDictionary,
_dictionary: Option<&BrotliDictionary>,
_dictionary_hash: &[u16],
_data: &[u8],
_ring_buffer_mask: usize,
Expand Down

0 comments on commit 25c1ad7

Please sign in to comment.