Use Option::unwrap_or_else.

This commit is contained in:
Dan Gohman
2017-10-03 12:53:28 -07:00
parent d4438f4006
commit 97b877bb9c

View File

@@ -187,21 +187,18 @@ impl FuncEnvironment for StandaloneRuntime {
self.the_heap.unwrap(), self.the_heap.unwrap(),
"multiple heaps not supported yet" "multiple heaps not supported yet"
); );
let grow_mem_func = match self.has_grow_memory { let grow_mem_func = self.has_grow_memory.unwrap_or_else(|| {
Some(grow_mem_func) => grow_mem_func, let sig_ref = pos.func.import_signature(Signature {
None => { call_conv: CallConv::Native,
let sig_ref = pos.func.import_signature(Signature { argument_bytes: None,
call_conv: CallConv::Native, argument_types: vec![ArgumentType::new(I32)],
argument_bytes: None, return_types: vec![ArgumentType::new(I32)],
argument_types: vec![ArgumentType::new(I32)], });
return_types: vec![ArgumentType::new(I32)], pos.func.import_function(ExtFuncData {
}); name: FunctionName::new("grow_memory"),
pos.func.import_function(ExtFuncData { signature: sig_ref,
name: FunctionName::new("grow_memory"), })
signature: sig_ref, });
})
}
};
self.has_grow_memory = Some(grow_mem_func); self.has_grow_memory = Some(grow_mem_func);
let call_inst = pos.ins().call(grow_mem_func, &[val]); let call_inst = pos.ins().call(grow_mem_func, &[val]);
*pos.func.dfg.inst_results(call_inst).first().unwrap() *pos.func.dfg.inst_results(call_inst).first().unwrap()
@@ -220,21 +217,18 @@ impl FuncEnvironment for StandaloneRuntime {
self.the_heap.unwrap(), self.the_heap.unwrap(),
"multiple heaps not supported yet" "multiple heaps not supported yet"
); );
let cur_mem_func = match self.has_current_memory { let cur_mem_func = self.has_current_memory.unwrap_or_else(|| {
Some(cur_mem_func) => cur_mem_func, let sig_ref = pos.func.import_signature(Signature {
None => { call_conv: CallConv::Native,
let sig_ref = pos.func.import_signature(Signature { argument_bytes: None,
call_conv: CallConv::Native, argument_types: Vec::new(),
argument_bytes: None, return_types: vec![ArgumentType::new(I32)],
argument_types: Vec::new(), });
return_types: vec![ArgumentType::new(I32)], pos.func.import_function(ExtFuncData {
}); name: FunctionName::new("current_memory"),
pos.func.import_function(ExtFuncData { signature: sig_ref,
name: FunctionName::new("current_memory"), })
signature: sig_ref, });
})
}
};
self.has_current_memory = Some(cur_mem_func); self.has_current_memory = Some(cur_mem_func);
let call_inst = pos.ins().call(cur_mem_func, &[]); let call_inst = pos.ins().call(cur_mem_func, &[]);
*pos.func.dfg.inst_results(call_inst).first().unwrap() *pos.func.dfg.inst_results(call_inst).first().unwrap()