@@ -436,8 +436,7 @@ impl<T: SliceWrapperMut<u32> + SliceWrapper<u32> + BasicHashComputer> AnyHasher
436436 }
437437 }
438438 if dictionary. is_some ( ) && self . buckets_ . USE_DICTIONARY ( ) != 0 && !is_match_found {
439- is_match_found = SearchInStaticDictionary (
440- dictionary. unwrap ( ) ,
439+ is_match_found = dictionary. unwrap ( ) . search_static_item (
441440 dictionary_hash,
442441 self ,
443442 & data[ cur_ix_masked..] ,
@@ -825,8 +824,7 @@ impl<Alloc: alloc::Allocator<u16> + alloc::Allocator<u32>> AnyHasher for H9<Allo
825824 }
826825 if !is_match_found && dictionary. is_some ( ) {
827826 let ( _, cur_data) = data. split_at ( cur_ix_masked) ;
828- is_match_found = SearchInStaticDictionary (
829- dictionary. unwrap ( ) ,
827+ is_match_found = dictionary. unwrap ( ) . search_static_item (
830828 dictionary_hash,
831829 self ,
832830 cur_data,
@@ -1752,8 +1750,7 @@ impl<
17521750
17531751 if !is_match_found && dictionary. is_some ( ) {
17541752 let ( _, cur_data) = data. split_at ( cur_ix_masked) ;
1755- is_match_found = SearchInStaticDictionary (
1756- dictionary. unwrap ( ) ,
1753+ is_match_found = dictionary. unwrap ( ) . search_static_item (
17571754 dictionary_hash,
17581755 self ,
17591756 cur_data,
@@ -1859,98 +1856,91 @@ fn Hash14(data: &[u8]) -> u32 {
18591856 h >> ( 32i32 - 14i32 )
18601857}
18611858
1862- fn TestStaticDictionaryItem (
1863- dictionary : & BrotliDictionary ,
1864- item : usize ,
1865- data : & [ u8 ] ,
1866- max_length : usize ,
1867- max_backward : usize ,
1868- max_distance : usize ,
1869- h9_opts : H9Opts ,
1870- out : & mut HasherSearchResult ,
1871- ) -> i32 {
1872- let backward: usize ;
1873-
1874- let len: usize = item & 0x1fusize ;
1875- let dist: usize = item >> 5 ;
1876- let offset: usize =
1877- ( dictionary. offsets_by_length [ len] as usize ) . wrapping_add ( len. wrapping_mul ( dist) ) ;
1878- if len > max_length {
1879- return 0i32 ;
1880- }
1881- let matchlen: usize = FindMatchLengthWithLimit ( data, & dictionary. data [ offset..] , len) ;
1882- if matchlen. wrapping_add ( kCutoffTransformsCount as usize ) <= len || matchlen == 0usize {
1883- return 0i32 ;
1884- }
1885- {
1886- let cut: u64 = len. wrapping_sub ( matchlen) as u64 ;
1887- let transform_id: usize =
1859+ impl BrotliDictionary {
1860+ fn test_static_item (
1861+ & self ,
1862+ item : usize ,
1863+ data : & [ u8 ] ,
1864+ max_length : usize ,
1865+ max_backward : usize ,
1866+ max_distance : usize ,
1867+ h9_opts : H9Opts ,
1868+ out : & mut HasherSearchResult ,
1869+ ) -> bool {
1870+ let len = item & 0x1f ;
1871+ let dist = item >> 5 ;
1872+ let offset = ( self . offsets_by_length [ len] as usize ) . wrapping_add ( len. wrapping_mul ( dist) ) ;
1873+ if len > max_length {
1874+ return false ;
1875+ }
1876+ let matchlen: usize = FindMatchLengthWithLimit ( data, & self . data [ offset..] , len) ;
1877+ if matchlen. wrapping_add ( kCutoffTransformsCount as usize ) <= len || matchlen == 0 {
1878+ return false ;
1879+ }
1880+
1881+ let cut = len. wrapping_sub ( matchlen) as u64 ;
1882+ let transform_id =
18881883 ( cut << 2 ) . wrapping_add ( kCutoffTransforms >> cut. wrapping_mul ( 6 ) & 0x3f ) as usize ;
1889- backward = max_backward
1884+ let backward = max_backward
18901885 . wrapping_add ( dist)
18911886 . wrapping_add ( 1 )
1892- . wrapping_add ( transform_id << dictionary. size_bits_by_length [ len] as i32 ) ;
1893- }
1894- if backward > max_distance {
1895- return 0i32 ;
1896- }
1897- let score: u64 = BackwardReferenceScore ( matchlen, backward, h9_opts) ;
1898- if score < out. score {
1899- return 0i32 ;
1887+ . wrapping_add ( transform_id << self . size_bits_by_length [ len] ) ;
1888+
1889+ if backward > max_distance {
1890+ return false ;
1891+ }
1892+ let score = BackwardReferenceScore ( matchlen, backward, h9_opts) ;
1893+ if score < out. score {
1894+ return false ;
1895+ }
1896+ out. len = matchlen;
1897+ out. len_x_code = len ^ matchlen;
1898+ out. distance = backward;
1899+ out. score = score;
1900+ true
19001901 }
1901- out. len = matchlen;
1902- out. len_x_code = len ^ matchlen;
1903- out. distance = backward;
1904- out. score = score;
1905- 1i32
1906- }
19071902
1908- fn SearchInStaticDictionary < HasherType : AnyHasher > (
1909- dictionary : & BrotliDictionary ,
1910- dictionary_hash : & [ u16 ] ,
1911- handle : & mut HasherType ,
1912- data : & [ u8 ] ,
1913- max_length : usize ,
1914- max_backward : usize ,
1915- max_distance : usize ,
1916- out : & mut HasherSearchResult ,
1917- shallow : bool ,
1918- ) -> bool {
1919- let mut key: usize ;
1920- let mut i: usize ;
1921- let mut is_match_found = false ;
1922- let opts = handle. Opts ( ) ;
1923- let xself: & mut Struct1 = handle. GetHasherCommon ( ) ;
1924- if xself. dict_num_matches < xself. dict_num_lookups >> 7 {
1925- return false ;
1926- }
1927- key = ( Hash14 ( data) << 1 ) as usize ; //FIXME: works for any kind of hasher??
1928- i = 0usize ;
1929- while i < if shallow { 1 } else { 2 } {
1930- {
1931- let item: usize = dictionary_hash[ key] as usize ;
1903+ fn search_static_item < HasherType : AnyHasher > (
1904+ & self ,
1905+ dictionary_hash : & [ u16 ] ,
1906+ handle : & mut HasherType ,
1907+ data : & [ u8 ] ,
1908+ max_length : usize ,
1909+ max_backward : usize ,
1910+ max_distance : usize ,
1911+ out : & mut HasherSearchResult ,
1912+ shallow : bool ,
1913+ ) -> bool {
1914+ let mut is_match_found = false ;
1915+ let opts = handle. Opts ( ) ;
1916+ let xself = handle. GetHasherCommon ( ) ;
1917+ if xself. dict_num_matches < xself. dict_num_lookups >> 7 {
1918+ return false ;
1919+ }
1920+ let mut key = ( Hash14 ( data) << 1 ) as usize ; //FIXME: works for any kind of hasher??
1921+ let iterations = if shallow { 1 } else { 2 } ;
1922+ for _ in 0 ..iterations {
1923+ let item = dictionary_hash[ key] as usize ;
19321924 xself. dict_num_lookups = xself. dict_num_lookups . wrapping_add ( 1 ) ;
1933- if item != 0usize {
1934- let item_matches: i32 = TestStaticDictionaryItem (
1935- dictionary,
1925+ if item != 0 {
1926+ if self . test_static_item (
19361927 item,
19371928 data,
19381929 max_length,
19391930 max_backward,
19401931 max_distance,
19411932 opts,
19421933 out,
1943- ) ;
1944- if item_matches != 0 {
1934+ ) {
19451935 xself. dict_num_matches = xself. dict_num_matches . wrapping_add ( 1 ) ;
19461936 is_match_found = true ;
19471937 }
19481938 }
1939+ key += 1 ;
19491940 }
1950- i = i . wrapping_add ( 1 ) ;
1951- key = key . wrapping_add ( 1 ) ;
1941+
1942+ is_match_found
19521943 }
1953- is_match_found
19541944}
19551945
19561946impl < Alloc : alloc:: Allocator < u16 > + alloc:: Allocator < u32 > > CloneWithAlloc < Alloc >
0 commit comments