From 25c1ad76432171bab51f9ef51cc703e091eb7d25 Mon Sep 17 00:00:00 2001 From: Daniel Reiter Horn Date: Wed, 26 Sep 2018 14:44:59 -0700 Subject: [PATCH] remove dictionary access from catable brotli files --- src/enc/backward_references.rs | 42 +++++++++++++++---------------- src/enc/backward_references_hq.rs | 17 +++++++------ src/enc/encode.rs | 2 +- src/enc/hash_to_binary_tree.rs | 2 +- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/enc/backward_references.rs b/src/enc/backward_references.rs index 931f1655..2ae572dc 100755 --- a/src/enc/backward_references.rs +++ b/src/enc/backward_references.rs @@ -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, @@ -268,7 +268,7 @@ impl + SliceWrapper + BasicHashComputer> AnyHasher } fn FindLongestMatch(&mut self, - dictionary: &BrotliDictionary, + dictionary: Option<&BrotliDictionary>, dictionary_hash: &[u16], data: &[u8], ring_buffer_mask: usize, @@ -384,8 +384,8 @@ impl + SliceWrapper + 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))..], @@ -648,7 +648,7 @@ impl + alloc::Allocator> AnyHasher for H9, dictionary_hash: &[u16], data: &[u8], ring_buffer_mask: usize, @@ -749,9 +749,9 @@ impl + alloc::Allocator> AnyHasher for H9 + alloc } fn FindLongestMatch(&mut self, - dictionary: &BrotliDictionary, + dictionary: Option<&BrotliDictionary>, dictionary_hash: &[u16], data: &[u8], ring_buffer_mask: usize, @@ -1080,9 +1080,9 @@ impl + 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, @@ -1357,7 +1357,7 @@ impl + alloc::Allocator> AnyHasher ringbuffer_mask); } fn FindLongestMatch(&mut self, - dictionary: &BrotliDictionary, + dictionary: Option<&BrotliDictionary>, dictionary_hash: &[u16], data: &[u8], ring_buffer_mask: usize, @@ -1451,7 +1451,7 @@ impl + alloc::Allocator> Default }, }) */ -fn CreateBackwardReferences(dictionary: &BrotliDictionary, +fn CreateBackwardReferences(dictionary: Option<&BrotliDictionary>, dictionary_hash: &[u16], num_bytes: usize, mut position: usize, @@ -1642,7 +1642,7 @@ pub fn BrotliCreateBackwardReferences + 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, @@ -1657,7 +1657,7 @@ pub fn BrotliCreateBackwardReferences + alloc::Allo } else { super::backward_references_hq::BrotliCreateZopfliBackwardReferences( alloc, - dictionary, + if params.catable {None} else {Some(dictionary)}, num_bytes, position, ringbuffer, @@ -1672,7 +1672,7 @@ pub fn BrotliCreateBackwardReferences + alloc::Allo } } &mut UnionHasher::H2(ref mut hasher) => { - CreateBackwardReferences(dictionary, + CreateBackwardReferences(if params.catable {None} else {Some(dictionary)}, &kStaticDictionaryHash[..], num_bytes, position, @@ -1687,7 +1687,7 @@ pub fn BrotliCreateBackwardReferences + alloc::Allo num_literals) } &mut UnionHasher::H3(ref mut hasher) => { - CreateBackwardReferences(dictionary, + CreateBackwardReferences(if params.catable {None} else {Some(dictionary)}, &kStaticDictionaryHash[..], num_bytes, position, @@ -1702,7 +1702,7 @@ pub fn BrotliCreateBackwardReferences + alloc::Allo num_literals) } &mut UnionHasher::H4(ref mut hasher) => { - CreateBackwardReferences(dictionary, + CreateBackwardReferences(if params.catable {None} else {Some(dictionary)}, &kStaticDictionaryHash[..], num_bytes, position, @@ -1717,7 +1717,7 @@ pub fn BrotliCreateBackwardReferences + alloc::Allo num_literals) } &mut UnionHasher::H5(ref mut hasher) => { - CreateBackwardReferences(dictionary, + CreateBackwardReferences(if params.catable {None} else {Some(dictionary)}, &kStaticDictionaryHash[..], num_bytes, position, @@ -1732,7 +1732,7 @@ pub fn BrotliCreateBackwardReferences + alloc::Allo num_literals) } &mut UnionHasher::H6(ref mut hasher) => { - CreateBackwardReferences(dictionary, + CreateBackwardReferences(if params.catable {None} else {Some(dictionary)}, &kStaticDictionaryHash[..], num_bytes, position, @@ -1747,7 +1747,7 @@ pub fn BrotliCreateBackwardReferences + alloc::Allo num_literals) } &mut UnionHasher::H9(ref mut hasher) => { - CreateBackwardReferences(dictionary, + CreateBackwardReferences(if params.catable {None} else {Some(dictionary)}, &kStaticDictionaryHash[..], num_bytes, position, @@ -1762,7 +1762,7 @@ pub fn BrotliCreateBackwardReferences + alloc::Allo num_literals) } &mut UnionHasher::H54(ref mut hasher) => { - CreateBackwardReferences(dictionary, + CreateBackwardReferences(if params.catable {None} else {Some(dictionary)}, &kStaticDictionaryHash[..], num_bytes, position, diff --git a/src/enc/backward_references_hq.rs b/src/enc/backward_references_hq.rs index 8bf02296..7dbe5114 100755 --- a/src/enc/backward_references_hq.rs +++ b/src/enc/backward_references_hq.rs @@ -390,7 +390,7 @@ pub fn StitchToPreviousBlockH10, } fn FindAllMatchesH10, Buckets: Allocable+SliceWrapperMut+SliceWrapper, Params:H10Params>( handle : &mut H10, - dictionary : & BrotliDictionary, + dictionary : Option<&BrotliDictionary>, data : & [u8], ring_buffer_mask : usize, cur_ix : usize, @@ -490,13 +490,14 @@ fn FindAllMatchesH10, Buckets: Allocable+ 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); @@ -1171,7 +1172,7 @@ pub fn BrotliZopfliComputeShortestPath, Params:H10Params, AllocF:Allocator>( m : &mut AllocF, - dictionary: &BrotliDictionary, + dictionary: Option<&BrotliDictionary>, num_bytes : usize, position : usize, ringbuffer : & [u8], @@ -1332,7 +1333,7 @@ pub fn BrotliCreateZopfliBackwardReferences + Allocator+SliceWrapperMut+SliceWrapper, Params:H10Params>( alloc : &mut Alloc, - dictionary: &BrotliDictionary, + dictionary: Option<&BrotliDictionary>, num_bytes : usize, position : usize, ringbuffer : & [u8], @@ -1682,7 +1683,7 @@ pub fn BrotliCreateHqZopfliBackwardReferences + Allocator+SliceWrapperMut+SliceWrapper, Params: H10Params>( alloc : &mut Alloc, - dictionary: &BrotliDictionary, + dictionary: Option<&BrotliDictionary>, num_bytes : usize, position : usize, ringbuffer : & [u8], diff --git a/src/enc/encode.rs b/src/enc/encode.rs index 0444d0ec..707a66d6 100755 --- a/src/enc/encode.rs +++ b/src/enc/encode.rs @@ -1419,7 +1419,7 @@ pub fn BrotliEncoderSetCustomDictionary 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 { diff --git a/src/enc/hash_to_binary_tree.rs b/src/enc/hash_to_binary_tree.rs index e4f5cac4..b74bc3d8 100755 --- a/src/enc/hash_to_binary_tree.rs +++ b/src/enc/hash_to_binary_tree.rs @@ -230,7 +230,7 @@ impl, } fn FindLongestMatch(&mut self, - _dictionary: &BrotliDictionary, + _dictionary: Option<&BrotliDictionary>, _dictionary_hash: &[u16], _data: &[u8], _ring_buffer_mask: usize,