1
0

Replace some "if let" statements with "matches!" macro for better formatting

This commit is contained in:
Jeff 2024-11-05 22:07:54 -05:00
parent 3330939128
commit 9650183c73

View File

@ -222,10 +222,15 @@ impl<'src> Parser<'src> {
} }
fn optimize_statement(&mut self) { fn optimize_statement(&mut self) {
if let Some( if matches!(
[Operation::LoadBoolean | Operation::LoadConstant, Operation::LoadBoolean | Operation::LoadConstant, Operation::Jump, Operation::Equal | Operation::Less | Operation::LessEqual], self.get_end_of_statement(),
) = self.get_end_of_statement() Some([
{ Operation::LoadBoolean | Operation::LoadConstant,
Operation::LoadBoolean | Operation::LoadConstant,
Operation::Jump,
Operation::Equal | Operation::Less | Operation::LessEqual
],)
) {
log::trace!("Optimizing boolean comparison"); log::trace!("Optimizing boolean comparison");
let mut instructions = self let mut instructions = self
@ -1017,10 +1022,15 @@ impl<'src> Parser<'src> {
self.advance()?; self.advance()?;
self.parse_expression()?; self.parse_expression()?;
if let Some( if matches!(
[Operation::LoadBoolean, Operation::LoadBoolean, Operation::Jump, Operation::Equal | Operation::Less | Operation::LessEqual], self.get_end_of_statement(),
) = self.get_end_of_statement() Some([
{ Operation::LoadBoolean,
Operation::LoadBoolean,
Operation::Jump,
Operation::Equal | Operation::Less | Operation::LessEqual
],)
) {
self.chunk.instructions_mut().pop(); self.chunk.instructions_mut().pop();
self.chunk.instructions_mut().pop(); self.chunk.instructions_mut().pop();
} }
@ -1152,10 +1162,15 @@ impl<'src> Parser<'src> {
self.parse_expression()?; self.parse_expression()?;
if let Some( if matches!(
[Operation::LoadBoolean, Operation::LoadBoolean, Operation::Jump, Operation::Equal | Operation::Less | Operation::LessEqual], self.get_end_of_statement(),
) = self.get_end_of_statement() Some([
{ Operation::LoadBoolean,
Operation::LoadBoolean,
Operation::Jump,
Operation::Equal | Operation::Less | Operation::LessEqual
],)
) {
self.chunk.instructions_mut().pop(); self.chunk.instructions_mut().pop();
self.chunk.instructions_mut().pop(); self.chunk.instructions_mut().pop();
self.chunk.instructions_mut().pop(); self.chunk.instructions_mut().pop();