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,9 +187,7 @@ 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,
None => {
let sig_ref = pos.func.import_signature(Signature { let sig_ref = pos.func.import_signature(Signature {
call_conv: CallConv::Native, call_conv: CallConv::Native,
argument_bytes: None, argument_bytes: None,
@@ -200,8 +198,7 @@ impl FuncEnvironment for StandaloneRuntime {
name: FunctionName::new("grow_memory"), name: FunctionName::new("grow_memory"),
signature: sig_ref, 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,9 +217,7 @@ 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,
None => {
let sig_ref = pos.func.import_signature(Signature { let sig_ref = pos.func.import_signature(Signature {
call_conv: CallConv::Native, call_conv: CallConv::Native,
argument_bytes: None, argument_bytes: None,
@@ -233,8 +228,7 @@ impl FuncEnvironment for StandaloneRuntime {
name: FunctionName::new("current_memory"), name: FunctionName::new("current_memory"),
signature: sig_ref, 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()