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:
Nick Fitzgerald
2021-10-25 15:51:55 -07:00
parent 06a93d3346
commit e3a423c3e8
3 changed files with 10 additions and 8 deletions

View File

@@ -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();