Skip to content

Commit

Permalink
remove error branch from LUT if it is unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyYato committed Apr 8, 2024
1 parent bfafdac commit 9149056
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions logos-codegen/src/generator/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,18 @@ impl<'a> Generator<'a> {
})
.collect::<TokenStream>();

let jumps = &jumps;
let may_error = table.iter().any(|&idx| idx == 0);

let jumps = jumps.as_slice();
let table = table.iter().copied().map(|idx| &jumps[idx as usize]);

let jumps = if may_error { jumps } else { &jumps[1..] };
let error_branch = if may_error {
Some(quote!(Jump::__ => #miss))
} else {
None
};

quote! {
enum Jump {
#(#jumps,)*
Expand All @@ -105,7 +114,7 @@ impl<'a> Generator<'a> {

match LUT[#byte as usize] {
#branches
Jump::__ => #miss,
#error_branch
}
}
}
Expand Down

0 comments on commit 9149056

Please sign in to comment.