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