diff --git a/src/enc/backward_references/hash_to_binary_tree.rs b/src/enc/backward_references/hash_to_binary_tree.rs index 1ec2fec0..82a16926 100755 --- a/src/enc/backward_references/hash_to_binary_tree.rs +++ b/src/enc/backward_references/hash_to_binary_tree.rs @@ -438,11 +438,7 @@ where let mut matches_offset = 0usize; let cur_ix_masked: usize = cur_ix & ring_buffer_mask; let max_comp_len: usize = core::cmp::min(max_length, 128usize); - let should_reroot_tree: i32 = if !!(max_length >= 128usize) { - 1i32 - } else { - 0i32 - }; + let should_reroot_tree = max_length >= 128; let key = xself.HashBytes(&data[cur_ix_masked..]); let forest: &mut [u32] = xself.forest.slice_mut(); let mut prev_ix: usize = xself.buckets_.slice()[key] as usize; @@ -451,7 +447,7 @@ where let mut best_len_left: usize = 0usize; let mut best_len_right: usize = 0usize; let mut depth_remaining: usize; - if should_reroot_tree != 0 { + if should_reroot_tree { xself.buckets_.slice_mut()[key] = cur_ix as u32; } depth_remaining = 64usize; @@ -460,7 +456,7 @@ where let backward: usize = cur_ix.wrapping_sub(prev_ix); let prev_ix_masked: usize = prev_ix & ring_buffer_mask; if backward == 0usize || backward > max_backward || depth_remaining == 0usize { - if should_reroot_tree != 0 { + if should_reroot_tree { forest[node_left] = xself.invalid_pos_; forest[node_right] = xself.invalid_pos_; } @@ -484,7 +480,7 @@ where matches_offset += 1; } if len >= max_comp_len { - if should_reroot_tree != 0 { + if should_reroot_tree { forest[node_left] = forest[LeftChildIndexH10!(xself, prev_ix)]; forest[node_right] = forest[RightChildIndexH10!(xself, prev_ix)]; } @@ -494,14 +490,14 @@ where > data[prev_ix_masked.wrapping_add(len)] as i32 { best_len_left = len; - if should_reroot_tree != 0 { + if should_reroot_tree { forest[node_left] = prev_ix as u32; } node_left = RightChildIndexH10!(xself, prev_ix); prev_ix = forest[node_left] as usize; } else { best_len_right = len; - if should_reroot_tree != 0 { + if should_reroot_tree { forest[node_right] = prev_ix as u32; } node_right = LeftChildIndexH10!(xself, prev_ix); diff --git a/src/enc/backward_references/hq.rs b/src/enc/backward_references/hq.rs index 62ad3876..5d27b9ee 100755 --- a/src/enc/backward_references/hq.rs +++ b/src/enc/backward_references/hq.rs @@ -139,11 +139,7 @@ pub fn BrotliZopfliCreateCommands( let len_code: usize = ZopfliNodeLengthCode(next) as usize; let max_distance: usize = brotli_min_size_t(block_start.wrapping_add(pos), max_backward_limit); - let is_dictionary: i32 = if !!(distance > max_distance.wrapping_add(gap)) { - 1i32 - } else { - 0i32 - }; + let is_dictionary = distance > max_distance.wrapping_add(gap); let dist_code: usize = ZopfliNodeDistanceCode(next) as usize; InitCommand( &mut commands[i], @@ -153,7 +149,7 @@ pub fn BrotliZopfliCreateCommands( len_code, dist_code, ); - if is_dictionary == 0 && (dist_code > 0usize) { + if !is_dictionary && dist_code > 0 { dist_cache[3] = dist_cache[2]; dist_cache[2] = dist_cache[1]; dist_cache[1] = dist_cache[0]; @@ -882,12 +878,7 @@ fn UpdateNodes>( { let mut match_: BackwardMatch = BackwardMatch(matches[j]); let dist: usize = match_.distance() as usize; - let is_dictionary_match: i32 = - if !!(dist > max_distance.wrapping_add(gap)) { - 1i32 - } else { - 0i32 - }; + let is_dictionary_match = dist > max_distance.wrapping_add(gap); let dist_code: usize = dist.wrapping_add(16).wrapping_sub(1); let mut dist_symbol: u16 = 0; let mut distextra: u32 = 0; @@ -908,13 +899,13 @@ fn UpdateNodes>( ); let max_match_len: usize = BackwardMatchLength(&mut match_); if len < max_match_len - && (is_dictionary_match != 0 || max_match_len > max_zopfli_len) + && (is_dictionary_match || max_match_len > max_zopfli_len) { len = max_match_len; } while len <= max_match_len { { - let len_code: usize = if is_dictionary_match != 0 { + let len_code: usize = if is_dictionary_match { BackwardMatchLengthCode(&mut match_) } else { len @@ -1480,7 +1471,7 @@ pub fn BrotliCreateHqZopfliBackwardReferences< } else { >::AllocatedMemory::default() }; - if !!(0i32 == 0) && (matches_size != 0usize) { + if matches_size != 0 { for (dst, src) in new_array .slice_mut() .split_at_mut(matches_size) diff --git a/src/enc/backward_references/mod.rs b/src/enc/backward_references/mod.rs index 30dbc512..f19eb325 100755 --- a/src/enc/backward_references/mod.rs +++ b/src/enc/backward_references/mod.rs @@ -367,7 +367,7 @@ impl + SliceWrapper + BasicHashComputer> AnyHasher let mut best_len: usize = best_len_in; let cached_backward: usize = distance_cache[0] as usize; let mut prev_ix: usize = cur_ix.wrapping_sub(cached_backward); - let mut is_match_found: i32 = 0i32; + let mut is_match_found = false; out.len_x_code = 0usize; if prev_ix < cur_ix { prev_ix &= ring_buffer_mask as u32 as usize; @@ -388,7 +388,7 @@ impl + SliceWrapper + BasicHashComputer> AnyHasher self.buckets_.slice_mut()[key as usize] = cur_ix as u32; return true; } else { - is_match_found = 1i32; + is_match_found = true; } } } @@ -440,12 +440,12 @@ impl + SliceWrapper + BasicHashComputer> AnyHasher out.distance = backward; out.score = score; compare_char = data[cur_ix_masked.wrapping_add(best_len)] as i32; - is_match_found = 1i32; + is_match_found = true; } } } } - if dictionary.is_some() && self.buckets_.USE_DICTIONARY() != 0 && (is_match_found == 0) { + if dictionary.is_some() && self.buckets_.USE_DICTIONARY() != 0 && !is_match_found { is_match_found = SearchInStaticDictionary( dictionary.unwrap(), dictionary_hash, @@ -455,13 +455,13 @@ impl + SliceWrapper + BasicHashComputer> AnyHasher max_backward.wrapping_add(gap), max_distance, out, - 1i32, + true, ); } self.buckets_.slice_mut() [(key as usize).wrapping_add((cur_ix >> 3).wrapping_rem(bucket_sweep as usize))] = cur_ix as u32; - is_match_found != 0 + is_match_found } } impl> BasicHashComputer for H2Sub { @@ -735,7 +735,7 @@ impl + alloc::Allocator> AnyHasher for H9 + alloc::Allocator> AnyHasher for H9 + alloc::Allocator> AnyHasher for H9 ring_buffer_mask { break; } @@ -833,7 +833,7 @@ impl + alloc::Allocator> AnyHasher for H9 + alloc::Allocator> AnyHasher for H9 bool { let opts = self.Opts(); let cur_ix_masked: usize = cur_ix & ring_buffer_mask; - let mut is_match_found: i32 = 0i32; + let mut is_match_found = false; let mut best_score: u64 = out.score; let mut best_len: usize = out.len; let mut i: usize; @@ -1707,7 +1707,7 @@ impl< out.len = best_len; out.distance = backward; out.score = best_score; - is_match_found = 1i32; + is_match_found = true; } } } @@ -1763,7 +1763,7 @@ impl< out.len = best_len; out.distance = backward; out.score = best_score; - is_match_found = 1i32; + is_match_found = true; } } } @@ -1772,7 +1772,7 @@ impl< cur_ix as u32; *num_ref_mut = num_ref_mut.wrapping_add(1); } - if is_match_found == 0 && dictionary.is_some() { + if !is_match_found && dictionary.is_some() { let (_, cur_data) = data.split_at(cur_ix_masked); is_match_found = SearchInStaticDictionary( dictionary.unwrap(), @@ -1783,10 +1783,10 @@ impl< max_backward.wrapping_add(gap), max_distance, out, - 0i32, + false, ); } - is_match_found != 0 + is_match_found } } @@ -1936,19 +1936,19 @@ fn SearchInStaticDictionary( max_backward: usize, max_distance: usize, out: &mut HasherSearchResult, - shallow: i32, -) -> i32 { + shallow: bool, +) -> bool { let mut key: usize; let mut i: usize; - let mut is_match_found: i32 = 0i32; + let mut is_match_found = false; let opts = handle.Opts(); let xself: &mut Struct1 = handle.GetHasherCommon(); if xself.dict_num_matches < xself.dict_num_lookups >> 7 { - return 0i32; + return false; } key = (Hash14(data) << 1) as usize; //FIXME: works for any kind of hasher?? i = 0usize; - while i < if shallow != 0 { 1u32 } else { 2u32 } as usize { + while i < if shallow { 1 } else { 2 } { { let item: usize = dictionary_hash[key] as usize; xself.dict_num_lookups = xself.dict_num_lookups.wrapping_add(1); @@ -1965,7 +1965,7 @@ fn SearchInStaticDictionary( ); if item_matches != 0 { xself.dict_num_matches = xself.dict_num_matches.wrapping_add(1); - is_match_found = 1i32; + is_match_found = true; } } } diff --git a/src/enc/brotli_bit_stream.rs b/src/enc/brotli_bit_stream.rs index 5e4d15d1..d111f0f6 100755 --- a/src/enc/brotli_bit_stream.rs +++ b/src/enc/brotli_bit_stream.rs @@ -1977,13 +1977,9 @@ fn EncodeContextMap>( i = i.wrapping_add(1); } { - let use_rle: i32 = if !!(max_run_length_prefix > 0u32) { - 1i32 - } else { - 0i32 - }; - BrotliWriteBits(1, use_rle as (u64), storage_ix, storage); - if use_rle != 0 { + let use_rle = max_run_length_prefix > 0; + BrotliWriteBits(1, u64::from(use_rle), storage_ix, storage); + if use_rle { BrotliWriteBits( 4, max_run_length_prefix.wrapping_sub(1) as (u64), diff --git a/src/enc/cluster.rs b/src/enc/cluster.rs index 9398b4da..ac348d86 100755 --- a/src/enc/cluster.rs +++ b/src/enc/cluster.rs @@ -48,9 +48,9 @@ fn brotli_max_double(a: super::util::floatX, b: super::util::floatX) -> super::u #[inline(always)] fn HistogramPairIsLess(p1: &HistogramPair, p2: &HistogramPair) -> bool { if p1.cost_diff != p2.cost_diff { - !!(p1.cost_diff > p2.cost_diff) + p1.cost_diff > p2.cost_diff } else { - !!(p1.idx2.wrapping_sub(p1.idx1) > p2.idx2.wrapping_sub(p2.idx1)) + p1.idx2.wrapping_sub(p1.idx1) > p2.idx2.wrapping_sub(p2.idx1) } } diff --git a/src/enc/command.rs b/src/enc/command.rs index 81cfb118..80a4fae7 100755 --- a/src/enc/command.rs +++ b/src/enc/command.rs @@ -403,10 +403,10 @@ pub fn InitCommand( GetLengthCode( insertlen, copylen_code, - if !!((xself.dist_prefix_ as i32 & 0x3ff) == 0i32) { - 1i32 + if (xself.dist_prefix_ & 0x3ff) == 0 { + 1 } else { - 0i32 + 0 }, &mut xself.cmd_prefix_, ); diff --git a/src/enc/compress_fragment.rs b/src/enc/compress_fragment.rs index a1dcda3e..a9afd574 100755 --- a/src/enc/compress_fragment.rs +++ b/src/enc/compress_fragment.rs @@ -32,14 +32,9 @@ fn Hash(p: &[u8], shift: usize) -> u32 { let h: u64 = (BROTLI_UNALIGNED_LOAD64(p) << 24).wrapping_mul(kHashMul32 as (u64)); (h >> shift) as u32 } -fn IsMatch(p1: &[u8], p2: &[u8]) -> i32 { - if !!(BROTLI_UNALIGNED_LOAD32(p1) == BROTLI_UNALIGNED_LOAD32(p2) - && (p1[4] as i32 == p2[4] as i32)) - { - 1i32 - } else { - 0i32 - } + +fn IsMatch(p1: &[u8], p2: &[u8]) -> bool { + BROTLI_UNALIGNED_LOAD32(p1) == BROTLI_UNALIGNED_LOAD32(p2) && (p1[4] as i32 == p2[4] as i32) } fn BuildAndStoreLiteralPrefixCode>( @@ -224,14 +219,14 @@ fn EmitInsertLen( } } -fn ShouldUseUncompressedMode(delta: isize, insertlen: usize, literal_ratio: usize) -> i32 { - let compressed: usize = delta as usize; +fn ShouldUseUncompressedMode(delta: isize, insertlen: usize, literal_ratio: usize) -> bool { + let compressed = delta as usize; if compressed.wrapping_mul(50) > insertlen { - 0i32 - } else if !!(literal_ratio > 980usize) { - 1i32 + false + } else if literal_ratio > 980 { + true } else { - 0i32 + false } } fn RewindBitPosition(new_storage_ix: usize, storage_ix: &mut usize, storage: &mut [u8]) { @@ -550,7 +545,7 @@ fn EmitCopyLen( } } -fn ShouldMergeBlock(data: &[u8], len: usize, depths: &[u8]) -> i32 { +fn ShouldMergeBlock(data: &[u8], len: usize, depths: &[u8]) -> bool { let mut histo: [usize; 256] = [0; 256]; static kSampleRate: usize = 43usize; let mut i: usize; @@ -579,11 +574,7 @@ fn ShouldMergeBlock(data: &[u8], len: usize, depths: &[u8]) -> i32 { } i = i.wrapping_add(1); } - if !!(r >= 0.0 as super::util::floatX) { - 1i32 - } else { - 0i32 - } + r >= 0.0 } } @@ -783,7 +774,7 @@ fn BrotliCompressFragmentFastImpl>( } next_hash = Hash(&input_ptr[next_ip..], shift); candidate = ip_index.wrapping_sub(last_distance as usize); - if IsMatch(&input_ptr[ip_index..], &input_ptr[candidate..]) != 0 + if IsMatch(&input_ptr[ip_index..], &input_ptr[candidate..]) && candidate < ip_index { table[hash as usize] = @@ -793,7 +784,7 @@ fn BrotliCompressFragmentFastImpl>( candidate = base_ip.wrapping_add(table[hash as usize] as usize); table[hash as usize] = ip_index.wrapping_sub(base_ip) as i32; } - if IsMatch(&input_ptr[ip_index..], &input_ptr[candidate..]) != 0 { + if IsMatch(&input_ptr[ip_index..], &input_ptr[candidate..]) { break; } } @@ -832,8 +823,7 @@ fn BrotliCompressFragmentFastImpl>( (next_emit as isize) - (metablock_start as isize), insert, literal_ratio, - ) != 0 - { + ) { EmitUncompressedMetaBlock( &input_ptr[metablock_start..], base.wrapping_sub(metablock_start), @@ -918,7 +908,7 @@ fn BrotliCompressFragmentFastImpl>( table[cur_hash as usize] = ip_index.wrapping_sub(base_ip) as i32; } } - while IsMatch(&input_ptr[ip_index..], &input_ptr[candidate..]) != 0 { + while IsMatch(&input_ptr[ip_index..], &input_ptr[candidate..]) { let base: usize = ip_index; let matched: usize = (5usize).wrapping_add(FindMatchLengthWithLimit( &input_ptr[candidate + 5..], @@ -991,8 +981,7 @@ fn BrotliCompressFragmentFastImpl>( block_size = brotli_min_size_t(input_size, kMergeBlockSize); if input_size > 0 && (total_block_size.wrapping_add(block_size) <= (1i32 << 20) as usize) - && (ShouldMergeBlock(&input_ptr[input_index..], block_size, &mut lit_depth[..]) - != 0) + && ShouldMergeBlock(&input_ptr[input_index..], block_size, &mut lit_depth[..]) { total_block_size = total_block_size.wrapping_add(block_size); UpdateBits( @@ -1027,8 +1016,7 @@ fn BrotliCompressFragmentFastImpl>( next_emit as isize - metablock_start as isize, insert, literal_ratio, - ) != 0 - { + ) { EmitUncompressedMetaBlock( &input_ptr[metablock_start..], ip_end.wrapping_sub(metablock_start), diff --git a/src/enc/compress_fragment_two_pass.rs b/src/enc/compress_fragment_two_pass.rs index 248af9dc..e5eba72f 100755 --- a/src/enc/compress_fragment_two_pass.rs +++ b/src/enc/compress_fragment_two_pass.rs @@ -152,14 +152,9 @@ fn Hash(p: &[u8], shift: usize, length: usize) -> u32 { (h >> shift) as u32 } -fn IsMatch(p1: &[u8], p2: &[u8], length: usize) -> i32 { - if BROTLI_UNALIGNED_LOAD32(p1) == BROTLI_UNALIGNED_LOAD32(p2) { - if length == 4 { - return 1; - } - return ((p1[4] as i32 == p2[4] as i32) && (p1[5] as i32 == p2[5] as i32)) as i32; - } - 0 +fn IsMatch(p1: &[u8], p2: &[u8], length: usize) -> bool { + BROTLI_UNALIGNED_LOAD32(p1) == BROTLI_UNALIGNED_LOAD32(p2) + && (length == 4 || (p1[4] == p2[4] && p1[5] == p2[5])) } #[allow(unused_assignments)] @@ -228,7 +223,7 @@ fn CreateCommands( next_hash = Hash(&base_ip[next_ip..], shift, min_match); 0i32; candidate = ip_index.wrapping_sub(last_distance as usize); - if IsMatch(&base_ip[ip_index..], &base_ip[candidate..], min_match) != 0 + if IsMatch(&base_ip[ip_index..], &base_ip[candidate..], min_match) && candidate < ip_index { table[(hash as usize)] = ip_index.wrapping_sub(0) as i32; @@ -243,7 +238,7 @@ fn CreateCommands( 0i32; table[(hash as usize)] = ip_index.wrapping_sub(0) as i32; } - if !(IsMatch(&base_ip[ip_index..], &base_ip[candidate..], min_match) == 0) { + if IsMatch(&base_ip[ip_index..], &base_ip[candidate..], min_match) { break; } } @@ -333,7 +328,7 @@ fn CreateCommands( } while ip_index.wrapping_sub(candidate) <= (1usize << 18).wrapping_sub(16) as isize as usize - && (IsMatch(&base_ip[ip_index..], &base_ip[candidate..], min_match) != 0) + && IsMatch(&base_ip[ip_index..], &base_ip[candidate..], min_match) { let base_index: usize = ip_index; let matched: usize = min_match.wrapping_add(FindMatchLengthWithLimit( @@ -414,10 +409,10 @@ fn CreateCommands( } } -fn ShouldCompress(input: &[u8], input_size: usize, num_literals: usize) -> i32 { +fn ShouldCompress(input: &[u8], input_size: usize, num_literals: usize) -> bool { let corpus_size: super::util::floatX = input_size as (super::util::floatX); if num_literals as (super::util::floatX) < 0.98 as super::util::floatX * corpus_size { - 1i32 + true } else { let mut literal_histo: [u32; 256] = [0; 256]; let max_total_bit_cost: super::util::floatX = @@ -433,11 +428,7 @@ fn ShouldCompress(input: &[u8], input_size: usize, num_literals: usize) -> i32 { } i = i.wrapping_add(43); } - if !!(BitsEntropy(&mut literal_histo[..], 256usize) < max_total_bit_cost) { - 1i32 - } else { - 0i32 - } + BitsEntropy(&mut literal_histo[..], 256) < max_total_bit_cost } } @@ -728,7 +719,7 @@ fn BrotliCompressFragmentTwoPassImpl>( &mut num_commands, ); } - if ShouldCompress(&base_ip[input_index..], block_size, num_literals) != 0 { + if ShouldCompress(&base_ip[input_index..], block_size, num_literals) { BrotliStoreMetaBlockHeader(block_size, 0i32, storage_ix, storage); BrotliWriteBits(13usize, 0, storage_ix, storage); StoreCommands( diff --git a/src/enc/encode.rs b/src/enc/encode.rs index 3ef71111..7b163114 100755 --- a/src/enc/encode.rs +++ b/src/enc/encode.rs @@ -304,7 +304,7 @@ pub fn set_parameter( if value != 0u32 && (value != 1u32) { return 0i32; } - params.disable_literal_context_modeling = if !!!(value == 0) { 1i32 } else { 0i32 }; + params.disable_literal_context_modeling = if value != 0 { 1i32 } else { 0i32 }; return 1i32; } if p as i32 == BrotliEncoderParameter::BROTLI_PARAM_SIZE_HINT as i32 { @@ -1354,9 +1354,17 @@ fn InitOrStitchToPreviousBlock + alloc::Allocator>( } table // FIXME: probably need a macro to do this without borrowing the whole EncoderStateStruct } -fn UpdateLastProcessedPos(s: &mut BrotliEncoderStateStruct) -> i32 { +fn UpdateLastProcessedPos(s: &mut BrotliEncoderStateStruct) -> bool { let wrapped_last_processed_pos: u32 = WrapPosition(s.last_processed_pos_); let wrapped_input_pos: u32 = WrapPosition(s.input_pos_); s.last_processed_pos_ = s.input_pos_; - if !!(wrapped_input_pos < wrapped_last_processed_pos) { - 1i32 - } else { - 0i32 - } + wrapped_input_pos < wrapped_last_processed_pos } fn MaxMetablockSize(params: &BrotliEncoderParams) -> usize { @@ -2036,7 +2040,7 @@ fn WriteMetaBlockInternal( mask: usize, last_flush_pos: u64, bytes: usize, - mut is_last: i32, + mut is_last: bool, literal_context_mode: ContextType, params: &BrotliEncoderParams, lit_scratch_space: &mut ::i32vec, @@ -2063,7 +2067,7 @@ fn WriteMetaBlockInternal( { let actual_is_last = is_last; if params.appendable { - is_last = 0; + is_last = false; } else { assert!(!params.catable); // Sanitize Params senforces this constraint } @@ -2088,7 +2092,7 @@ fn WriteMetaBlockInternal( dist_cache[..4].clone_from_slice(&saved_dist_cache[..4]); BrotliStoreUncompressedMetaBlock( alloc, - is_last, + is_last as i32, data, wrapped_last_flush_pos as usize, mask, @@ -2124,7 +2128,7 @@ fn WriteMetaBlockInternal( wrapped_last_flush_pos as usize, bytes, mask, - is_last, + is_last as i32, params, saved_dist_cache, commands, @@ -2141,7 +2145,7 @@ fn WriteMetaBlockInternal( wrapped_last_flush_pos as usize, bytes, mask, - is_last, + is_last as i32, params, saved_dist_cache, commands, @@ -2218,7 +2222,7 @@ fn WriteMetaBlockInternal( mask, prev_byte, prev_byte2, - is_last, + is_last as i32, &block_params, literal_context_mode, saved_dist_cache, @@ -2242,7 +2246,7 @@ fn WriteMetaBlockInternal( *storage_ix = last_bytes_bits as usize; BrotliStoreUncompressedMetaBlock( alloc, - is_last, + is_last as i32, data, wrapped_last_flush_pos as usize, mask, @@ -2306,10 +2310,11 @@ fn ChooseDistanceParams(params: &mut BrotliEncoderParams) { fn EncodeData( s: &mut BrotliEncoderStateStruct, - is_last: i32, - force_flush: i32, + is_last: bool, + force_flush: bool, out_size: &mut usize, - callback: &mut MetablockCallback, // mut output: &'a mut &'a mut [u8] + callback: &mut MetablockCallback, + // mut output: &'a mut &'a mut [u8] ) -> i32 where MetablockCallback: FnMut( @@ -2329,7 +2334,7 @@ where if s.is_last_block_emitted_ { return 0i32; } - if is_last != 0 { + if is_last { s.is_last_block_emitted_ = true; } if delta > InputBlockSize(s) as u64 { @@ -2422,7 +2427,7 @@ where if s.params.quality == 0i32 || s.params.quality == 1i32 { let mut table_size: usize = 0; { - if delta == 0 && (is_last == 0) { + if delta == 0 && !is_last { *out_size = catable_header_size; return 1i32; } @@ -2439,7 +2444,7 @@ where &mut s.m8, &mut data[((wrapped_last_processed_pos & mask) as usize)..], bytes as usize, - is_last, + is_last as i32, table, table_size, &mut s.cmd_depths_[..], @@ -2454,7 +2459,7 @@ where &mut s.m8, &mut data[((wrapped_last_processed_pos & mask) as usize)..], bytes as usize, - is_last, + is_last as i32, s.command_buf_.slice_mut(), s.literal_buf_.slice_mut(), table, @@ -2569,27 +2574,18 @@ where let max_literals: usize = max_length.wrapping_div(8); let max_commands: usize = max_length.wrapping_div(8); let processed_bytes: usize = s.input_pos_.wrapping_sub(s.last_flush_pos_) as usize; - let next_input_fits_metablock: i32 = - if !!(processed_bytes.wrapping_add(InputBlockSize(s)) <= max_length) { - 1i32 - } else { - 0i32 - }; - let should_flush: i32 = if !!(s.params.quality < 4i32 - && (s.num_literals_.wrapping_add(s.num_commands_) >= 0x2fffusize)) - { - 1i32 - } else { - 0i32 - }; - if is_last == 0 - && (force_flush == 0) - && (should_flush == 0) - && (next_input_fits_metablock != 0) - && (s.num_literals_ < max_literals) - && (s.num_commands_ < max_commands) + let next_input_fits_metablock = + processed_bytes.wrapping_add(InputBlockSize(s)) <= max_length; + let should_flush = + s.params.quality < 4 && s.num_literals_.wrapping_add(s.num_commands_) >= 0x2fff; + if !is_last + && !force_flush + && !should_flush + && next_input_fits_metablock + && s.num_literals_ < max_literals + && s.num_commands_ < max_commands { - if UpdateLastProcessedPos(s) != 0 { + if UpdateLastProcessedPos(s) { HasherReset(&mut s.hasher_); } *out_size = catable_header_size; @@ -2608,7 +2604,7 @@ where s.num_literals_ = s.num_literals_.wrapping_add(s.last_insert_len_); s.last_insert_len_ = 0usize; } - if is_last == 0 && (s.input_pos_ == s.last_flush_pos_) { + if !is_last && s.input_pos_ == s.last_flush_pos_ { *out_size = catable_header_size; return 1i32; } @@ -2647,7 +2643,7 @@ where | ((s.storage_.slice()[1 + (storage_ix >> 3)] as u16) << 8); s.last_bytes_bits_ = (storage_ix & 7u32 as usize) as u8; s.last_flush_pos_ = s.input_pos_; - if UpdateLastProcessedPos(s) != 0 { + if UpdateLastProcessedPos(s) { HasherReset(&mut s.hasher_); } let data = &s.ringbuffer_.data_mo.slice()[s.ringbuffer_.buffer_index..]; @@ -2752,7 +2748,7 @@ fn ProcessMetadata< } if s.input_pos_ != s.last_flush_pos_ { let mut avail_out: usize = s.available_out_; - let result: i32 = EncodeData(s, 0i32, 1i32, &mut avail_out, metablock_callback); + let result: i32 = EncodeData(s, false, true, &mut avail_out, metablock_callback); s.available_out_ = avail_out; if result == 0 { return 0i32; @@ -2886,19 +2882,17 @@ fn BrotliEncoderCompressStreamFast( || op as i32 != BrotliEncoderOperation::BROTLI_OPERATION_PROCESS as i32) { let block_size: usize = brotli_min_size_t(block_size_limit, *available_in); - let is_last: i32 = (*available_in == block_size - && (op as i32 == BrotliEncoderOperation::BROTLI_OPERATION_FINISH as i32)) - as i32; - let force_flush: i32 = (*available_in == block_size - && (op as i32 == BrotliEncoderOperation::BROTLI_OPERATION_FLUSH as i32)) - as i32; + let is_last = *available_in == block_size + && op == BrotliEncoderOperation::BROTLI_OPERATION_FINISH; + let force_flush = + *available_in == block_size && op == BrotliEncoderOperation::BROTLI_OPERATION_FLUSH; let max_out_size: usize = (2usize).wrapping_mul(block_size).wrapping_add(503); let mut inplace: i32 = 1i32; let storage: &mut [u8]; let mut storage_ix: usize = s.last_bytes_bits_ as usize; let mut table_size: usize = 0; - if force_flush != 0 && (block_size == 0usize) { + if force_flush && block_size == 0 { s.stream_state_ = BrotliEncoderStreamState::BROTLI_STREAM_FLUSH_REQUESTED; { { @@ -2921,7 +2915,7 @@ fn BrotliEncoderCompressStreamFast( &mut s.m8, &(next_in_array)[*next_in_offset..], block_size, - is_last, + is_last as i32, table, table_size, &mut s.cmd_depths_[..], @@ -2936,7 +2930,7 @@ fn BrotliEncoderCompressStreamFast( &mut s.m8, &(next_in_array)[*next_in_offset..], block_size, - is_last, + is_last as i32, command_buf.slice_mut(), literal_buf.slice_mut(), table, @@ -2965,10 +2959,10 @@ fn BrotliEncoderCompressStreamFast( s.last_bytes_ = storage[(storage_ix >> 3)] as u16 | ((storage[1 + (storage_ix >> 3)] as u16) << 8); s.last_bytes_bits_ = (storage_ix & 7u32 as usize) as u8; - if force_flush != 0 { + if force_flush { s.stream_state_ = BrotliEncoderStreamState::BROTLI_STREAM_FLUSH_REQUESTED; } - if is_last != 0 { + if is_last { s.stream_state_ = BrotliEncoderStreamState::BROTLI_STREAM_FINISHED; } { @@ -3099,20 +3093,10 @@ pub fn BrotliEncoderCompressStream< && (remaining_block_size == 0usize || op as i32 != BrotliEncoderOperation::BROTLI_OPERATION_PROCESS as i32) { - let is_last: i32 = if !!(*available_in == 0usize - && (op as i32 == BrotliEncoderOperation::BROTLI_OPERATION_FINISH as i32)) - { - 1i32 - } else { - 0i32 - }; - let force_flush: i32 = if !!(*available_in == 0usize - && (op as i32 == BrotliEncoderOperation::BROTLI_OPERATION_FLUSH as i32)) - { - 1i32 - } else { - 0i32 - }; + let is_last = + *available_in == 0 && op == BrotliEncoderOperation::BROTLI_OPERATION_FINISH; + let force_flush = + *available_in == 0 && op == BrotliEncoderOperation::BROTLI_OPERATION_FLUSH; UpdateSizeHint(s, *available_in); let mut avail_out = s.available_out_; @@ -3123,10 +3107,10 @@ pub fn BrotliEncoderCompressStream< if result == 0 { return 0i32; } - if force_flush != 0 { + if force_flush { s.stream_state_ = BrotliEncoderStreamState::BROTLI_STREAM_FLUSH_REQUESTED; } - if is_last != 0 { + if is_last { s.stream_state_ = BrotliEncoderStreamState::BROTLI_STREAM_FINISHED; } { @@ -3146,8 +3130,8 @@ pub fn BrotliEncoderCompressStream< } pub fn BrotliEncoderIsFinished(s: &BrotliEncoderStateStruct) -> i32 { - if !!(s.stream_state_ as i32 == BrotliEncoderStreamState::BROTLI_STREAM_FINISHED as i32 - && (BrotliEncoderHasMoreOutput(s) == 0)) + if s.stream_state_ == BrotliEncoderStreamState::BROTLI_STREAM_FINISHED + && BrotliEncoderHasMoreOutput(s) == 0 { 1i32 } else { @@ -3156,7 +3140,7 @@ pub fn BrotliEncoderIsFinished(s: &BrotliEncoderStateStruct< } pub fn BrotliEncoderHasMoreOutput(s: &BrotliEncoderStateStruct) -> i32 { - if !!(s.available_out_ != 0usize) { + if s.available_out_ != 0 { 1i32 } else { 0i32 @@ -3220,7 +3204,13 @@ pub fn BrotliEncoderWriteData< output: &'a mut &'a mut [u8], metablock_callback: &mut MetablockCallback, ) -> i32 { - let ret = EncodeData(s, is_last, force_flush, out_size, metablock_callback); + let ret = EncodeData( + s, + is_last != 0, + force_flush != 0, + out_size, + metablock_callback, + ); *output = s.storage_.slice_mut(); ret } diff --git a/src/enc/entropy_encode.rs b/src/enc/entropy_encode.rs index eeb394d9..446b582b 100644 --- a/src/enc/entropy_encode.rs +++ b/src/enc/entropy_encode.rs @@ -67,9 +67,9 @@ pub struct SortHuffmanTree {} impl HuffmanComparator for SortHuffmanTree { fn Cmp(&self, v0: &HuffmanTree, v1: &HuffmanTree) -> bool { if v0.total_count_ != v1.total_count_ { - !!(v0.total_count_ < v1.total_count_) + v0.total_count_ < v1.total_count_ } else { - !!(v0.index_right_or_value_ as i32 > v1.index_right_or_value_ as i32) + v0.index_right_or_value_ > v1.index_right_or_value_ } } } @@ -448,12 +448,12 @@ pub fn DecideOverRleUse( } i = i.wrapping_add(reps); } - *use_rle_for_non_zero = if !!(total_reps_non_zero > count_reps_non_zero.wrapping_mul(2)) { + *use_rle_for_non_zero = if total_reps_non_zero > count_reps_non_zero.wrapping_mul(2) { 1i32 } else { 0i32 }; - *use_rle_for_zero = if !!(total_reps_zero > count_reps_zero.wrapping_mul(2)) { + *use_rle_for_zero = if total_reps_zero > count_reps_zero.wrapping_mul(2) { 1i32 } else { 0i32 diff --git a/src/enc/static_dict.rs b/src/enc/static_dict.rs index d6f597cd..84de5916 100755 --- a/src/enc/static_dict.rs +++ b/src/enc/static_dict.rs @@ -342,30 +342,30 @@ pub fn slowFindMatchLengthWithLimit(s1: &[u8], s2: &[u8], limit: usize) -> usize pub fn IsMatch(dictionary: &BrotliDictionary, w: DictWord, data: &[u8], max_length: usize) -> i32 { if w.l as usize > max_length { - 0i32 + 0 } else { let offset: usize = (dictionary.offsets_by_length[w.l as usize] as usize) .wrapping_add((w.len() as usize).wrapping_mul(w.idx() as usize)); let dict = &dictionary.data.split_at(offset).1; if w.transform() as i32 == 0i32 { - if !!(FindMatchLengthWithLimit(dict, data, w.l as usize) == w.l as usize) { - 1i32 + if FindMatchLengthWithLimit(dict, data, w.l as usize) == w.l as usize { + 1 } else { - 0i32 + 0 } } else if w.transform() as i32 == 10i32 { - if !!(dict[0] as i32 >= b'a' as i32 + if dict[0] as i32 >= b'a' as i32 && (dict[0] as i32 <= b'z' as i32) && (dict[0] as i32 ^ 32i32 == data[0] as i32) && (FindMatchLengthWithLimit( dict.split_at(1).1, data.split_at(1).1, (w.len() as u32).wrapping_sub(1) as usize, - ) == (w.len() as u32).wrapping_sub(1) as usize)) + ) == (w.len() as u32).wrapping_sub(1) as usize) { - 1i32 + 1 } else { - 0i32 + 0 } } else { let mut i: usize; @@ -374,15 +374,15 @@ pub fn IsMatch(dictionary: &BrotliDictionary, w: DictWord, data: &[u8], max_leng { if dict[i] as i32 >= b'a' as i32 && (dict[i] as i32 <= b'z' as i32) { if dict[i] as i32 ^ 32i32 != data[i] as i32 { - return 0i32; + return 0; } } else if dict[i] as i32 != data[i] as i32 { - return 0i32; + return 0; } } i = i.wrapping_add(1); } - 1i32 + 1 } } } @@ -959,38 +959,28 @@ pub fn BrotliFindAllStaticDictionaryMatches( ); } } else { - let is_all_caps: i32 = if !!(w.transform() as i32 != kUppercaseFirst as i32) { - 1i32 - } else { - 0i32 - }; + let is_all_caps = w.transform() != kUppercaseFirst; if IsMatch(dictionary, w, data, max_length) == 0 { - { - continue; - } + continue; } //eprint!("AVdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( - id.wrapping_add( - (if is_all_caps != 0 { 44i32 } else { 9i32 } as usize).wrapping_mul(n), - ), + id.wrapping_add((if is_all_caps { 44usize } else { 9usize }).wrapping_mul(n)), l, l, matches, ); has_found_match = 1i32; if l.wrapping_add(1) >= max_length { - { - continue; - } + continue; } let s: &[u8] = data.split_at(l as usize).1; if s[0] as i32 == b' ' as i32 { //eprint!("AWdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 68i32 } else { 4i32 } as usize).wrapping_mul(n), + (if is_all_caps { 68usize } else { 4usize }).wrapping_mul(n), ), l.wrapping_add(1), l, @@ -1000,7 +990,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("AXdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 87i32 } else { 66i32 } as usize).wrapping_mul(n), + (if is_all_caps { 87usize } else { 66usize }).wrapping_mul(n), ), l.wrapping_add(1), l, @@ -1010,8 +1000,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("AYdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 97i32 } else { 69i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 97usize } else { 69usize }).wrapping_mul(n), ), l.wrapping_add(2), l, @@ -1022,8 +1011,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("AZdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 101i32 } else { 79i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 101usize } else { 79usize }).wrapping_mul(n), ), l.wrapping_add(1), l, @@ -1033,8 +1021,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("BAdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 114i32 } else { 88i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 114usize } else { 88usize }).wrapping_mul(n), ), l.wrapping_add(2), l, @@ -1045,8 +1032,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("BBdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 112i32 } else { 99i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 112usize } else { 99usize }).wrapping_mul(n), ), l.wrapping_add(1), l, @@ -1056,8 +1042,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("BCdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 107i32 } else { 58i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 107usize } else { 58usize }).wrapping_mul(n), ), l.wrapping_add(2), l, @@ -1068,7 +1053,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("BDdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 94i32 } else { 74i32 } as usize).wrapping_mul(n), + (if is_all_caps { 94usize } else { 74usize }).wrapping_mul(n), ), l.wrapping_add(1), l, @@ -1078,8 +1063,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("BEdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 113i32 } else { 78i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 113usize } else { 78usize }).wrapping_mul(n), ), l.wrapping_add(1), l, @@ -1090,8 +1074,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("BFdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 105i32 } else { 104i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 105usize } else { 104usize }).wrapping_mul(n), ), l.wrapping_add(2), l, @@ -1101,8 +1084,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("BGdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 116i32 } else { 108i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 116usize } else { 108usize }).wrapping_mul(n), ), l.wrapping_add(2), l, @@ -1114,11 +1096,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( } } if max_length >= 5usize && (data[0] as i32 == b' ' as i32 || data[0] as i32 == b'.' as i32) { - let is_space: i32 = if !!(data[0] as i32 == b' ' as i32) { - 1i32 - } else { - 0i32 - }; + let is_space = data[0] == b' '; let mut offset: usize = kStaticDictionaryBuckets[Hash(data.split_at(1).1) as usize] as usize; let mut end: i32 = (offset == 0) as i32; @@ -1141,15 +1119,11 @@ pub fn BrotliFindAllStaticDictionaryMatches( max_length.wrapping_sub(1), ) == 0 { - { - continue; - } + continue; } //eprint!("BHdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( - id.wrapping_add( - (if is_space != 0 { 6i32 } else { 32i32 } as usize).wrapping_mul(n), - ), + id.wrapping_add((if is_space { 6usize } else { 32usize }).wrapping_mul(n)), l.wrapping_add(1), l, matches, @@ -1164,9 +1138,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( if s[0] as i32 == b' ' as i32 { //eprint!("BIdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( - id.wrapping_add( - (if is_space != 0 { 2i32 } else { 77i32 } as usize).wrapping_mul(n), - ), + id.wrapping_add((if is_space { 2usize } else { 77usize }).wrapping_mul(n)), l.wrapping_add(2), l, matches, @@ -1174,14 +1146,12 @@ pub fn BrotliFindAllStaticDictionaryMatches( } else if s[0] as i32 == b'(' as i32 { //eprint!("BJdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( - id.wrapping_add( - (if is_space != 0 { 89i32 } else { 67i32 } as usize).wrapping_mul(n), - ), + id.wrapping_add((if is_space { 89usize } else { 67usize }).wrapping_mul(n)), l.wrapping_add(2), l, matches, ); - } else if is_space != 0 { + } else if is_space { if s[0] as i32 == b',' as i32 { //eprint!("BKdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( @@ -1236,12 +1206,8 @@ pub fn BrotliFindAllStaticDictionaryMatches( } } } - } else if is_space != 0 { - let is_all_caps: i32 = if !!(w.transform() as i32 != kUppercaseFirst as i32) { - 1i32 - } else { - 0i32 - }; + } else if is_space { + let is_all_caps = w.transform() != kUppercaseFirst; if IsMatch( dictionary, @@ -1250,15 +1216,11 @@ pub fn BrotliFindAllStaticDictionaryMatches( max_length.wrapping_sub(1), ) == 0 { - { - continue; - } + continue; } //eprint!("CAdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( - id.wrapping_add( - (if is_all_caps != 0 { 85i32 } else { 30i32 } as usize).wrapping_mul(n), - ), + id.wrapping_add((if is_all_caps { 85usize } else { 30usize }).wrapping_mul(n)), l.wrapping_add(1), l, matches, @@ -1274,14 +1236,14 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("CBdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 83i32 } else { 15i32 } as usize).wrapping_mul(n), + (if is_all_caps { 83usize } else { 15usize }).wrapping_mul(n), ), l.wrapping_add(2), l, matches, ); } else if s[0] as i32 == b',' as i32 { - if is_all_caps == 0 { + if !is_all_caps { //eprint!("CCdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add((109usize).wrapping_mul(n)), @@ -1294,8 +1256,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("CDdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 111i32 } else { 65i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 111usize } else { 65usize }).wrapping_mul(n), ), l.wrapping_add(3), l, @@ -1306,8 +1267,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("CEdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 115i32 } else { 96i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 115usize } else { 96usize }).wrapping_mul(n), ), l.wrapping_add(2), l, @@ -1317,8 +1277,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("CFdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 117i32 } else { 91i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 117usize } else { 91usize }).wrapping_mul(n), ), l.wrapping_add(3), l, @@ -1330,8 +1289,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("CGdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 110i32 } else { 118i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 110usize } else { 118usize }).wrapping_mul(n), ), l.wrapping_add(3), l, @@ -1341,8 +1299,7 @@ pub fn BrotliFindAllStaticDictionaryMatches( //eprint!("CHdding match {} {} {} {}\n", w.len(), w.transform(), w.idx(), 666); AddMatch( id.wrapping_add( - (if is_all_caps != 0 { 119i32 } else { 120i32 } as usize) - .wrapping_mul(n), + (if is_all_caps { 119usize } else { 120usize }).wrapping_mul(n), ), l.wrapping_add(3), l, diff --git a/src/enc/utf8_util.rs b/src/enc/utf8_util.rs index a1d23605..2ecc4934 100755 --- a/src/enc/utf8_util.rs +++ b/src/enc/utf8_util.rs @@ -68,7 +68,7 @@ pub fn BrotliIsMostlyUTF8( size_utf8 = size_utf8.wrapping_add(bytes_read); } } - if !!(size_utf8 as (super::util::floatX) > min_fraction * length as (super::util::floatX)) { + if size_utf8 as (super::util::floatX) > min_fraction * length as (super::util::floatX) { 1i32 } else { 0i32