@@ -432,8 +432,7 @@ impl<T: SliceWrapperMut<u32> + SliceWrapper<u32> + BasicHashComputer> AnyHasher
432
432
}
433
433
}
434
434
if dictionary. is_some ( ) && self . buckets_ . USE_DICTIONARY ( ) != 0 && !is_match_found {
435
- is_match_found = SearchInStaticDictionary (
436
- dictionary. unwrap ( ) ,
435
+ is_match_found = dictionary. unwrap ( ) . search_static_item (
437
436
dictionary_hash,
438
437
self ,
439
438
& data[ cur_ix_masked..] ,
@@ -821,8 +820,7 @@ impl<Alloc: alloc::Allocator<u16> + alloc::Allocator<u32>> AnyHasher for H9<Allo
821
820
}
822
821
if !is_match_found && dictionary. is_some ( ) {
823
822
let ( _, cur_data) = data. split_at ( cur_ix_masked) ;
824
- is_match_found = SearchInStaticDictionary (
825
- dictionary. unwrap ( ) ,
823
+ is_match_found = dictionary. unwrap ( ) . search_static_item (
826
824
dictionary_hash,
827
825
self ,
828
826
cur_data,
@@ -1752,8 +1750,7 @@ impl<
1752
1750
1753
1751
if !is_match_found && dictionary. is_some ( ) {
1754
1752
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 (
1757
1754
dictionary_hash,
1758
1755
self ,
1759
1756
cur_data,
@@ -1849,98 +1846,91 @@ fn Hash14(data: &[u8]) -> u32 {
1849
1846
h >> ( 32i32 - 14i32 )
1850
1847
}
1851
1848
1852
- fn TestStaticDictionaryItem (
1853
- dictionary : & BrotliDictionary ,
1854
- item : usize ,
1855
- data : & [ u8 ] ,
1856
- max_length : usize ,
1857
- max_backward : usize ,
1858
- max_distance : usize ,
1859
- h9_opts : H9Opts ,
1860
- out : & mut HasherSearchResult ,
1861
- ) -> i32 {
1862
- let backward: usize ;
1863
-
1864
- let len: usize = item & 0x1fusize ;
1865
- let dist: usize = item >> 5 ;
1866
- let offset: usize =
1867
- ( dictionary. offsets_by_length [ len] as usize ) . wrapping_add ( len. wrapping_mul ( dist) ) ;
1868
- if len > max_length {
1869
- return 0i32 ;
1870
- }
1871
- let matchlen: usize = FindMatchLengthWithLimit ( data, & dictionary. data [ offset..] , len) ;
1872
- if matchlen. wrapping_add ( kCutoffTransformsCount as usize ) <= len || matchlen == 0usize {
1873
- return 0i32 ;
1874
- }
1875
- {
1876
- let cut: u64 = len. wrapping_sub ( matchlen) as u64 ;
1877
- let transform_id: usize =
1849
+ impl BrotliDictionary {
1850
+ fn test_static_item (
1851
+ & self ,
1852
+ item : usize ,
1853
+ data : & [ u8 ] ,
1854
+ max_length : usize ,
1855
+ max_backward : usize ,
1856
+ max_distance : usize ,
1857
+ h9_opts : H9Opts ,
1858
+ out : & mut HasherSearchResult ,
1859
+ ) -> bool {
1860
+ let len = item & 0x1f ;
1861
+ let dist = item >> 5 ;
1862
+ let offset = ( self . offsets_by_length [ len] as usize ) . wrapping_add ( len. wrapping_mul ( dist) ) ;
1863
+ if len > max_length {
1864
+ return false ;
1865
+ }
1866
+ let matchlen: usize = FindMatchLengthWithLimit ( data, & self . data [ offset..] , len) ;
1867
+ if matchlen. wrapping_add ( kCutoffTransformsCount as usize ) <= len || matchlen == 0 {
1868
+ return false ;
1869
+ }
1870
+
1871
+ let cut = len. wrapping_sub ( matchlen) as u64 ;
1872
+ let transform_id =
1878
1873
( cut << 2 ) . wrapping_add ( kCutoffTransforms >> cut. wrapping_mul ( 6 ) & 0x3f ) as usize ;
1879
- backward = max_backward
1874
+ let backward = max_backward
1880
1875
. wrapping_add ( dist)
1881
1876
. wrapping_add ( 1 )
1882
- . wrapping_add ( transform_id << dictionary. size_bits_by_length [ len] as i32 ) ;
1883
- }
1884
- if backward > max_distance {
1885
- return 0i32 ;
1886
- }
1887
- let score: u64 = BackwardReferenceScore ( matchlen, backward, h9_opts) ;
1888
- if score < out. score {
1889
- return 0i32 ;
1877
+ . wrapping_add ( transform_id << self . size_bits_by_length [ len] ) ;
1878
+
1879
+ if backward > max_distance {
1880
+ return false ;
1881
+ }
1882
+ let score = BackwardReferenceScore ( matchlen, backward, h9_opts) ;
1883
+ if score < out. score {
1884
+ return false ;
1885
+ }
1886
+ out. len = matchlen;
1887
+ out. len_x_code = len ^ matchlen;
1888
+ out. distance = backward;
1889
+ out. score = score;
1890
+ true
1890
1891
}
1891
- out. len = matchlen;
1892
- out. len_x_code = len ^ matchlen;
1893
- out. distance = backward;
1894
- out. score = score;
1895
- 1i32
1896
- }
1897
1892
1898
- fn SearchInStaticDictionary < HasherType : AnyHasher > (
1899
- dictionary : & BrotliDictionary ,
1900
- dictionary_hash : & [ u16 ] ,
1901
- handle : & mut HasherType ,
1902
- data : & [ u8 ] ,
1903
- max_length : usize ,
1904
- max_backward : usize ,
1905
- max_distance : usize ,
1906
- out : & mut HasherSearchResult ,
1907
- shallow : bool ,
1908
- ) -> bool {
1909
- let mut key: usize ;
1910
- let mut i: usize ;
1911
- let mut is_match_found = false ;
1912
- let opts = handle. Opts ( ) ;
1913
- let xself: & mut Struct1 = handle. GetHasherCommon ( ) ;
1914
- if xself. dict_num_matches < xself. dict_num_lookups >> 7 {
1915
- return false ;
1916
- }
1917
- key = ( Hash14 ( data) << 1 ) as usize ; //FIXME: works for any kind of hasher??
1918
- i = 0usize ;
1919
- while i < if shallow { 1 } else { 2 } {
1920
- {
1921
- let item: usize = dictionary_hash[ key] as usize ;
1893
+ fn search_static_item < HasherType : AnyHasher > (
1894
+ & self ,
1895
+ dictionary_hash : & [ u16 ] ,
1896
+ handle : & mut HasherType ,
1897
+ data : & [ u8 ] ,
1898
+ max_length : usize ,
1899
+ max_backward : usize ,
1900
+ max_distance : usize ,
1901
+ out : & mut HasherSearchResult ,
1902
+ shallow : bool ,
1903
+ ) -> bool {
1904
+ let mut is_match_found = false ;
1905
+ let opts = handle. Opts ( ) ;
1906
+ let xself = handle. GetHasherCommon ( ) ;
1907
+ if xself. dict_num_matches < xself. dict_num_lookups >> 7 {
1908
+ return false ;
1909
+ }
1910
+ let mut key = ( Hash14 ( data) << 1 ) as usize ; //FIXME: works for any kind of hasher??
1911
+ let iterations = if shallow { 1 } else { 2 } ;
1912
+ for _ in 0 ..iterations {
1913
+ let item = dictionary_hash[ key] as usize ;
1922
1914
xself. dict_num_lookups = xself. dict_num_lookups . wrapping_add ( 1 ) ;
1923
- if item != 0usize {
1924
- let item_matches: i32 = TestStaticDictionaryItem (
1925
- dictionary,
1915
+ if item != 0 {
1916
+ if self . test_static_item (
1926
1917
item,
1927
1918
data,
1928
1919
max_length,
1929
1920
max_backward,
1930
1921
max_distance,
1931
1922
opts,
1932
1923
out,
1933
- ) ;
1934
- if item_matches != 0 {
1924
+ ) {
1935
1925
xself. dict_num_matches = xself. dict_num_matches . wrapping_add ( 1 ) ;
1936
1926
is_match_found = true ;
1937
1927
}
1938
1928
}
1929
+ key += 1 ;
1939
1930
}
1940
- i = i . wrapping_add ( 1 ) ;
1941
- key = key . wrapping_add ( 1 ) ;
1931
+
1932
+ is_match_found
1942
1933
}
1943
- is_match_found
1944
1934
}
1945
1935
1946
1936
impl < Alloc : alloc:: Allocator < u16 > + alloc:: Allocator < u32 > > CloneWithAlloc < Alloc >
0 commit comments