Skip to content

Commit

Permalink
Fix #72 with more explicit control flow that mimics the basic blocks …
Browse files Browse the repository at this point in the history
…of C brotli compress_fragment.c
  • Loading branch information
danielrh committed Mar 31, 2022
1 parent 558f4bf commit 0c107fa
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/enc/compress_fragment.rs
Expand Up @@ -712,7 +712,7 @@ fn BrotliCompressFragmentFastImpl<AllocHT:alloc::Allocator<HuffmanTree>>(m: &mut
storage_ix,
storage);
let mut code_block_selection: CodeBlockState = CodeBlockState::EMIT_COMMANDS;
loop {
'continue_to_next_block: loop {
let mut ip_index: usize;
if code_block_selection == CodeBlockState::EMIT_COMMANDS {
cmd_histo[..128].clone_from_slice(&kCmdHistoSeed[..]);
Expand Down Expand Up @@ -806,7 +806,7 @@ fn BrotliCompressFragmentFastImpl<AllocHT:alloc::Allocator<HuffmanTree>>(m: &mut
input_index = base;
next_emit = input_index;
code_block_selection = CodeBlockState::NEXT_BLOCK;
break;
continue 'continue_to_next_block;
} else {
EmitLongInsertLen(insert,
cmd_depth,
Expand Down Expand Up @@ -849,7 +849,7 @@ fn BrotliCompressFragmentFastImpl<AllocHT:alloc::Allocator<HuffmanTree>>(m: &mut
next_emit = ip_index;
if ip_index >= ip_limit {
code_block_selection = CodeBlockState::EMIT_REMAINDER;
break;
continue 'continue_to_next_block;
}
{
assert!(ip_index >= 3);
Expand Down Expand Up @@ -896,7 +896,7 @@ fn BrotliCompressFragmentFastImpl<AllocHT:alloc::Allocator<HuffmanTree>>(m: &mut
next_emit = ip_index;
if ip_index >= ip_limit {
code_block_selection = CodeBlockState::EMIT_REMAINDER;
break;
continue 'continue_to_next_block;
}
{
assert!(ip_index >= 3);
Expand Down Expand Up @@ -929,7 +929,7 @@ fn BrotliCompressFragmentFastImpl<AllocHT:alloc::Allocator<HuffmanTree>>(m: &mut
}
}
code_block_selection = CodeBlockState::EMIT_REMAINDER;
continue;
continue 'continue_to_next_block;
} else if code_block_selection as i32 == CodeBlockState::EMIT_REMAINDER as i32 {
input_index = input_index.wrapping_add(block_size);
input_size = input_size.wrapping_sub(block_size);
Expand All @@ -945,7 +945,7 @@ fn BrotliCompressFragmentFastImpl<AllocHT:alloc::Allocator<HuffmanTree>>(m: &mut
mlen_storage_ix,
storage);
code_block_selection = CodeBlockState::EMIT_COMMANDS;
continue;
continue 'continue_to_next_block;;
}
if next_emit < ip_end {
let insert: usize = ip_end.wrapping_sub(next_emit);
Expand Down Expand Up @@ -987,6 +987,7 @@ fn BrotliCompressFragmentFastImpl<AllocHT:alloc::Allocator<HuffmanTree>>(m: &mut
}
next_emit = ip_end;
code_block_selection = CodeBlockState::NEXT_BLOCK;
continue 'continue_to_next_block;
} else if code_block_selection as i32 == CodeBlockState::NEXT_BLOCK as i32 {
if input_size > 0 {
metablock_start = input_index;
Expand All @@ -1008,7 +1009,7 @@ fn BrotliCompressFragmentFastImpl<AllocHT:alloc::Allocator<HuffmanTree>>(m: &mut
storage_ix,
storage);
code_block_selection = CodeBlockState::EMIT_COMMANDS;
continue;
continue 'continue_to_next_block;
}
break;
}
Expand Down

0 comments on commit 0c107fa

Please sign in to comment.