Remove some uses of foo.expect(&format!(...)) pattern
This eagerly evaluates the `format!` and produces a `String` with a heap allocation, regardless whether `foo` is `Some`/`Ok` or `None`/`Err`. Using `foo.unwrap_or_else(|| panic!(...))` makes it so that the error message formatting is only evaluated if `foo` is `None`/`Err`.
This commit is contained in:
@@ -43,7 +43,7 @@ fn bench_sequential(c: &mut Criterion, modules: &[&str]) {
|
||||
|
||||
let engine = Engine::new(&config).expect("failed to create engine");
|
||||
let module = Module::from_file(&engine, &path)
|
||||
.expect(&format!("failed to load benchmark `{}`", path.display()));
|
||||
.unwrap_or_else(|_| panic!("failed to load benchmark `{}`", path.display()));
|
||||
let mut linker = Linker::new(&engine);
|
||||
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx).unwrap();
|
||||
|
||||
|
||||
@@ -349,7 +349,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
|
||||
to_bits: u8,
|
||||
) -> Self::I {
|
||||
let ext_mode = ExtMode::new(from_bits as u16, to_bits as u16)
|
||||
.expect(&format!("invalid extension: {} -> {}", from_bits, to_bits));
|
||||
.unwrap_or_else(|| panic!("invalid extension: {} -> {}", from_bits, to_bits));
|
||||
if is_signed {
|
||||
Inst::movsx_rm_r(ext_mode, RegMem::reg(from_reg), to_reg)
|
||||
} else {
|
||||
|
||||
@@ -236,7 +236,7 @@ fn extend_input_to_reg<C: LowerCtx<I = Inst>>(
|
||||
let ext_mode = match (input_size, requested_size) {
|
||||
(a, b) if a == b => return put_input_in_reg(ctx, spec),
|
||||
(1, 8) => return put_input_in_reg(ctx, spec),
|
||||
(a, b) => ExtMode::new(a, b).expect(&format!("invalid extension: {} -> {}", a, b)),
|
||||
(a, b) => ExtMode::new(a, b).unwrap_or_else(|| panic!("invalid extension: {} -> {}", a, b)),
|
||||
};
|
||||
|
||||
let src = input_to_reg_mem(ctx, spec);
|
||||
@@ -5847,11 +5847,13 @@ fn lower_insn_to_regs<C: LowerCtx<I = Inst>>(
|
||||
if ty_access == types::I64 {
|
||||
ctx.emit(Inst::mov64_rm_r(rm, data));
|
||||
} else {
|
||||
let ext_mode = ExtMode::new(ty_access.bits(), 64).expect(&format!(
|
||||
"invalid extension during AtomicLoad: {} -> {}",
|
||||
ty_access.bits(),
|
||||
64
|
||||
));
|
||||
let ext_mode = ExtMode::new(ty_access.bits(), 64).unwrap_or_else(|| {
|
||||
panic!(
|
||||
"invalid extension during AtomicLoad: {} -> {}",
|
||||
ty_access.bits(),
|
||||
64
|
||||
)
|
||||
});
|
||||
ctx.emit(Inst::movzx_rm_r(ext_mode, rm, data));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user