Update matches with single arm to be if-let statements

This commit is contained in:
Hernando Castano
2018-05-29 22:46:11 -04:00
parent de23bfac0a
commit e6e340fa0a
7 changed files with 91 additions and 158 deletions
+9 -15
View File
@@ -165,15 +165,12 @@ fn generate_stack_height_global(ctx: &mut Context, module: &mut elements::Module
// Try to find an existing global section.
for section in module.sections_mut() {
match *section {
elements::Section::Global(ref mut gs) => {
gs.entries_mut().push(global_entry);
if let elements::Section::Global(ref mut gs) = *section {
gs.entries_mut().push(global_entry);
let stack_height_global_idx = (gs.entries().len() as u32) - 1;
ctx.stack_height_global_idx = Some(stack_height_global_idx);
return;
}
_ => {}
let stack_height_global_idx = (gs.entries().len() as u32) - 1;
ctx.stack_height_global_idx = Some(stack_height_global_idx);
return;
}
}
@@ -233,14 +230,11 @@ fn compute_stack_cost(func_idx: u32, module: &elements::Module) -> Result<u32, E
fn instrument_functions(ctx: &mut Context, module: &mut elements::Module) -> Result<(), Error> {
for section in module.sections_mut() {
match *section {
elements::Section::Code(ref mut code_section) => {
for func_body in code_section.bodies_mut() {
let mut opcodes = func_body.code_mut();
instrument_function(ctx, opcodes)?;
}
if let elements::Section::Code(ref mut code_section) = *section {
for func_body in code_section.bodies_mut() {
let mut opcodes = func_body.code_mut();
instrument_function(ctx, opcodes)?;
}
_ => {}
}
}
Ok(())
+2 -3
View File
@@ -142,9 +142,8 @@ pub(crate) fn generate_thunks(
match *section {
elements::Section::Export(ref mut export_section) => {
for entry in export_section.entries_mut() {
match *entry.internal_mut() {
Internal::Function(ref mut function_idx) => fixup(function_idx),
_ => {}
if let Internal::Function(ref mut function_idx) = *entry.internal_mut() {
fixup(function_idx)
}
}
}